Re:$ sudo rm -rf / === NPM install
by wongarsu on Tuesday November 09, 2021 @02:32PM
(#29166311)
No:
There's still lots of ways to screw up a rm, like "rm -rf /*" or deleting your entire home directory, but a space after the initial / was apparently common enough that they eventually put a big failsafe for that in the GNU version.
[ Parent
| on HN ]
More serious than users fatfingering the command were scripts with code like
rm -rf /$MYVAR
If you don't set $MYVAR and don't set bash to error on unset variables you are in for trouble.I don't recall which one it is (u for unset perhaps?) but I cover this by starting every (bash, E and pipefail are not POSIX) script with `set -eEuo pipefail`. All should be the default IMO, I don't understand - other than back-compat - why you wouldn't want them.
Re:$ sudo rm -rf / === NPM install
by SAI_Peregrinus on Tuesday November 09, 2021 @09:05PM
(#29170288)
It's -u.
You can also prevent this by never using $VAR, and instead always using ${VAR:?} to exit with error if VAR is unset (or use one of the other options to provide a default).
Re:$ sudo rm -rf / === NPM install
by andrewmackrodt on Wednesday November 10, 2021 @09:28AM
(#29174960)
A lesson I learnt several years ago when I discovered that mktemp behaves differently on macOS versus the GNU version in Linux.
From that day onward I always make sure the first line of my bash scripts contains at least "set -e".
Re:$ sudo rm -rf / === NPM install
by johnmaguire on Tuesday November 09, 2021 @02:37PM
(#29166373)
I don't think OSX uses GNU tools unless you install them through brew.