Skip to content

Instantly share code, notes, and snippets.

@tian-im
Created October 23, 2011 07:28
Show Gist options
  • Save tian-im/1306994 to your computer and use it in GitHub Desktop.
Save tian-im/1306994 to your computer and use it in GitHub Desktop.
Shell script programming practices
# if else then in one line
[ $condition ] && echo 'true' || echo 'false'
# if argument empty then
local arg
echo ${arg:-default_value} # => default_value
arg=present
echo ${arg:-default_value} # => present
# if argument not empty then replace the text
# note that no regular expression could be applied
echo ${arg//t/t?} # => present?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment