Skip to content

Instantly share code, notes, and snippets.

@carsonip
Last active November 1, 2019 02:43
Show Gist options
  • Save carsonip/a7f66373ea1f572aa68a31364e3f4ca3 to your computer and use it in GitHub Desktop.
Save carsonip/a7f66373ea1f572aa68a31364e3f4ca3 to your computer and use it in GitHub Desktop.
Bash magic

Argument

echo $1 $2  # argument by position
echo $@  # all arguments

Default

echo ${x:-default value}  # equiv to python: "x or 'default value'"

Substring

echo ${parameter:offset:length}

Don't stop and also save exit status

set -e
EXIT_CODE=0
command || EXIT_CODE=$?
echo $EXIT_CODE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment