Some advanced bash scripting
medium.com
medium.com
Personally, I would also recommend using ShellCheck[2] to lint your scripts.
[1] http://www.kfirlavi.com/blog/2012/11/14/defensive-bash-progr...
> This will set the value of TMP to `/tmp/myproject` only if it has not been set.
This should read "if", not "only if". And it should read: "This will set the value of TMP to `/tmp/myproject` if it has not been set or if it is null."
The form that means 'if it has not been set' has no colon; it is
TMP=${TMP-/tmp/myproject}
See https://www.gnu.org/software/bash/manual/bash.html#Shell-Par... INPUT_FILE="${1:-/dev/stdin}"
Which sets the input to the first argument if there is one, or stdin if there isn't. My solution was a lot messier before I learned about parameter substitution. set -e
function foo {
false
echo foo
}
i=1
while [[ i -le 20 ]]; do
echo "$i $(foo)"
i=$((i+1))
done