Created
April 16, 2015 15:05
-
-
Save neilellis/22a725084fd839ee61f8 to your computer and use it in GitHub Desktop.
Some useful bash features
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eux | |
#e - error if non zero return value | |
#u - undefined variables trigger syntax error | |
#x - debug | |
#minus sign ADDS the flags | |
#plus sign REMOVES the flags | |
A=7 | |
#Double parenthesis after $ performs arithmetic | |
B=$(($A * 4)) | |
echo $B | |
#Double parenthesis in if statements allow arithemtic comparison | |
if (( $B > 25 )) | |
then | |
echo $B | |
echo ${C:-$((B+10))} | |
fi | |
set +u | |
#Double brackets allow proper variable usage not expansion | |
if [[ $1 == "thing" ]] | |
then | |
thing="Oops no args" | |
else | |
thing=$1 | |
fi | |
set -u | |
#Default value | |
echo ${1:-"Oops no args"} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment