sh
How do I make Bash’ tab complete automatically cycle through options OSX
Yes! I found the answer to the question at the following link at MacWorld put the following in .bashrc or .bash_login bind ‘”\t”:menu-complete’
How to output return code in shell?
echo $? >> /path/to/return_code $? has the return code of the last statement in bash.
use conditional in bash script to check string argument
What about the shorter : #!/bin/bash [[ $1 == A ]] && echo “A” || echo “not A” ? And a beginner version (identical logic) : #!/bin/bash if [[ $1 == A ]]; then echo “A” else echo “not A” fi Like Scott said, you have a syntax error (missing space). explanations I use boolean … Read more
systemctl status shows inactive dead
You have set Type=Forking, but your service doesn’t work. Try Type=oneshot You have a “&” your ExecStart line, which is not necessary. The service is disabled, which means it was not enabled to start at boot. You should run systemctl enable hello to set it to start at boot. You can check man systemd.directives to … Read more
How to check if two paths are equal in Bash?
Bash’s test commands have a -ef operator for this purpose: if [[ ./ -ef ~ ]]; then … if [[ ~/Desktop -ef /home/you/Desktop ]]; then … Here is the documentation for this operator: $ help test | grep -e -ef FILE1 -ef FILE2 True if file1 is a hard link to file2. $ help ‘[[‘ … Read more
How to test if string matches a regex in POSIX shell? (not bash)
The [[ … ]] are a bash-ism. You can make your test shell-agnostic by just using grep with a normal if: if echo “$string” | grep -q “My”; then echo “It’s there!” fi
Printing PDFs from Windows Command Line
I know this is and old question, but i was faced with the same problem recently and none of the answers worked for me: Couldn’t find an old Foxit Reader version As @pilkch said 2Printer adds a report page Adobe Reader opens a gui After searching a little more I found this: https://github.com/svishnevsky/PDFtoPrinter. It’s a … Read more
How to automate creation of new Xcode targets from Applescript/Automator/Shell Script
let me start with this script (for Xcode 4.2.1), Open an XCode project at /this/path/project.xcodeproj (done) Duplicate an existing target and rename it (not implemented) Edit the Build Settings of the new target (done) Add a group to the Source and Resources section, then rename them (done) Add source files to the groups, and add … Read more
Forcing cURL to get a password from the environment
This bash solution appears to best fit my needs. It’s decently secure, portable, and fast. #!/bin/bash SRV=”example.com” URL=”https://$SRV/path” curl –netrc-file <(cat <<<“machine $SRV login $USER password $PASSWORD”) “$URL” This uses process substitution (<( command ) runs command in a sub-shell to populate a file descriptor to be handed as a “file” to the parent command, … Read more