Bash-gotchas: Difference between revisions
Jump to navigation
Jump to search
(Created page with "Oddball things to remember when working in bash.. * Exit codes are not always honored in function calls when it is inline <pre> f() { echo "test"; exit 2 } f() { echo "test"...") |
mNo edit summary |
||
Line 32: | Line 32: | ||
eval `danger '; /bin/echo *'` | eval `danger '; /bin/echo *'` | ||
echo "$danger" | echo "$danger" | ||
</pre> | |||
* Lazy scripting can or will cause errs: | |||
<pre> | |||
unset FOO | |||
$ echo "$FOO" | |||
$ echo "1$FOO1" | |||
1 | |||
$ echo "1${FOO}1" | |||
11 | |||
$ FOO=bar | |||
$ echo "1${FOO}1" | |||
1bar1 | |||
$ echo "1$FOO1" | |||
1 | |||
</pre> | </pre> | ||
[[Category:bash]] | [[Category:bash]] |
Latest revision as of 14:08, 8 December 2021
Oddball things to remember when working in bash..
- Exit codes are not always honored in function calls when it is inline
f() { echo "test"; exit 2 } f() { echo "test" exit 2 }
- Breaking out of a function early can be a PITA
f() { foo=yes if [[ ${foo} = 'yes' ]]; then echo "blah" return 0 elif [[ $foo = 'no ]]; then echo "barf" return 1 else echo "baz" fi curl https//some.url }
- Eval can be useful to pull vars out of a function
danger() { danger="$*"; passback danger; } eval `danger '; /bin/echo *'` echo "$danger"
- Lazy scripting can or will cause errs:
unset FOO $ echo "$FOO" $ echo "1$FOO1" 1 $ echo "1${FOO}1" 11 $ FOO=bar $ echo "1${FOO}1" 1bar1 $ echo "1$FOO1" 1