Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>Line 468: rm -rf "$STEAMROOT/"*

Oh man, reading that line made me cringe.



Seriously, how do you use rm -rf anywhere in a script without copious if statements? It's quite easy to avoid this mistake.


TIL that this quick trick [1] also would have prevented this:

  ${STEAMROOT:?}
...where :? throws an error if the variable is unset or empty. (Still far too scary for my taste, though!)

[1] https://github.com/koalaman/shellcheck/wiki/SC2115


Or you just do

  set -euo pipefail
as the first thing in your bash script which you absolutely should do every single time.


Note that's bash not POSIX though right?


If you need an extra check in any API to do something really damaging, the problem is with the design of the API itself.

I generally just prefer not using Bash scripting, as it's very hard to compose functionality in it.


Or maybe just `set -o nounset`




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: