Bash
https://stackoverflow.com/questions/2500436/how-does-cat-eof-work-in-bash
http://goo.gl/ZThKCj - printing strings help
http://goo.gl/HnPkiq - arithmetic operator
http://goo.gl/g6xtca - arrays
http://goo.gl/xRHo3u - parameter expansion
https://github.com/aperezdc/perezdecastro.org/blob/master/stash/using-boolean-variables-in-bash.markdown - flag variables in bourne shell
https://kvz.io/blog/2013/11/21/bash-best-practices/ - boiler plate and best practice guide
Bash 4
http://clubmate.fi/upgrade-to-bash-4-in-mac-os-x/
Post upgrade to use bash 4 in script. change shebang line
#!/usr/local/bin/bash
Configure terminal to use it
# Add the new shell to the list of allowed shells
sudo bash -c 'echo /usr/local/bin/bash >> /etc/shells'
# Change to the new shell
chsh -s /usr/local/bin/bash
sed
appending newlines with mac: https://stackoverflow.com/questions/16576197/how-to-add-new-line-using-sed-mac
echo foo | sed 's/f/f\'$'\n/'
tokens=$(echo "$tokens" | sed ' /^[[:space:]]*}/a \
\
')
tokens=$(echo "${tokens}" | sed ' /^\s*$/d;s/},/}/;s/}/}\'$'\n\\\n/; ')
https://lists.freebsd.org/pipermail/freebsd-questions/2009-March/194500.html - example to safe replace with newlines
a="This
is
the
input
from the
web server"
b=`echo $a`
sed "s/foo/$b/"
https://taoofmac.com/space/cli/sed - examples
https://stackoverflow.com/questions/29613304/is-it-possible-to-escape-regex-metacharacters-reliably-with-sed - more whitespacing issues
awk
echo "${tokens}" | awk 'BEGIN { RS=""; FS=/,/; }; $0 ~ "[email protected]" { print }'
escaping quotes
wrap with single quote and expand variable
grep '^'"${APP_NAME}"''
args and help
http://spf13.com/post/easy-bash-scripting-with-shflags/ - documentation module
shflags
https://github.com/kward/shflags
Install
- Download
- link to path
ln ~/data/tools/shflags-1.2.2/shflags /usr/local/bin/shflags
- execute
lint/static analysis
https://github.com/koalaman/shellcheck
brew install shellcheck
execute
shellcheck script.sh