@cfriend, I'm not picking on you here. I just want to make a point for all users.
###ATTN: All Users -- Caution When Running Scripts
I strongly advise against running a script, any script, but particularly a shell script, that:
You didn't write yourself
OR
Did not come from a very trusted source, AND You do not understand
Shell Scripts can do just about anything, anything the user has proper permissions for.
As @cfriend just learned, the results can be catastrophic. Fortunately he has a backup. Most users I know don't have a proper/current backup.
If you have any doubts about any script, post the script here (in a new Topic), and ask for help.
I'm a novice shell scripter myself, but we do have a few very experienced folks here for almost every scripting language.
Glad I could be of service I won’t be making that mistake again.
RE: backups, with the exception of fiddling with system preferences, I am back up and running in under ten minutes thanks to good backups. I use Arq to back up to a micro SD, Amazon Drive, Dropbox, and a NAS in the closet. This is overkill, but I encourage anyone without multiple backups of your important files to look into it immediately.
No, that is not too much @cfriend Have 3 external hard disks in use. 2 x Time Machine and 1 x ChronoSync. With ChronoSync I synchronize my iMac and my MacBook, if times one fails I always have a current Mac at hand
Once in a while I also do such things. And it always happens when testing/debugging my own scripts, not scripts from others . Last time I managed to erase two-thirds of my /Applications folder before I noticed that something was going wrong.
Best thing to have in case of such misadventures is an exact (and recent) clone of the volume.
My feeling is that it may be a good rule of thumb to avoid, as much as possible, the sharing of any script that involves any kind of delete component, explicit or implicit.
(Even where the value of some kind of delete really does seem absolutely likely to outweigh the risks, better, I personally feel, to disable the delete by default in the script, and explain to the user what they would have to do to set a delete enabled option, while also explaining the risks and liabilities).
Perhaps there’s an argument for naming a thread like this ‘Caution when sharing or running scripts’ ?