|
|
|
|
|
by 1vuio0pswjnm7
1326 days ago
|
|
test ! "${configdir}"||rm -rf "~/${configdir}"
[ "${configdir}" ]&&rm -rf "~/${configdir}"
test x"${configdir}" = x""||rm -rf "~/${configdir}"
[ x"${configdir}" != x"" ]&&rm -rf "~/${configdir}"
This assumes NetBSD ash or Debian ash which is what I use. I write scripts for me, not for others and often end up using "quick one-off" scripts for years. After decades of using UNIX, I have never wiped a root directory accidentally (but there is still time). YMMV. |
|
You can also set the "-u" option (in Zsh, `setopt no_unset`) which at least will cause your script to crash with an error if you happen to forget this check. But then you have to remember to set that option as well!
Lua has a similar-ish problem with undefined variables being `nil`, but for the most part Lua is also rather strictly typed, and that will typically end up causing some kind of error deep inside a function call, rather than doing something dangerous silently.