3 ms·
I do this all the time for particularly scary yet infrequent scripts that I’m paranoid for accidentally executing. The simpler ones check an environment variab
by koolba 5y ago
I do this all the time for particularly scary yet infrequent scripts that I’m paranoid for accidentally executing.
The simpler ones check an environment variable such as RUN_SCARY_THINGY is set to “yes”.
The complex ones check that it has a timestamp that is within the past minute.
Accidentally run the script without exporting the right var and it prints a message suggesting a cup of coffee.
- Zecc 5y agoWhen writing and running SQL one-offs interactively, I will surround it with `if 1<>1 begin end` or comments, or add syntax errors at the top so that I won't accidentally run it without first selecting the part I want to run. I should get into the habit of writing `begin; rollback` instead for extra-safety. And I always write the WHERE clause before the DELETE or UPDATE keywords.
- chriswarbo 5y ago> And I always write the WHERE clause before the DELETE or UPDATE keywords. I sometimes get nervous typing 'rm -r' commands, since it starts with a very broad path, and only narrows-down as we type more, e.g. if we hit enter prematurely when typing 'rm -r ~/Downloads/archive.zip' we might delete our entire home directory, or all of our downloads. For this reason I often prefix dangerous steps with 'echo'; once I'm confident it's correct, I'll then run the script and double-check that variables/flags/etc. expanded as expected; and only then will I remove the echoes.
- twic 5y agoSimilarly, i sometimes start writing the command line with 'ls' or 'find', and then run it, and once i'm satisfied it describes the right things, i change the find to an rm.
- tux3 5y agoI always write rm <path> -rf for this reason (I was surprised to learn that on some systems, the flags are in a fixed position, at the start!)
- ndsipa_pomu 5y agoOne reason for having the flags before the <path> is so that you can terminate the flags by using '--'. This is especially useful to prevent dubious files being expanded that might start with '-' and be interpreted as flags that leads to unexpected results.
- tux3 5y agoNote that my Debian's `rm` happily supports terminating flags using `--` when necessary, so wanting to support `--` syntax doesn't have to come at the expense of writing -r last. Almost always, if I'm inputting `rm` manually in a shell, I don't need `--`; very few filenames on my disk start with -.
- leghifla 5y agoWhen I was still a student, I accidentally erased all my project source code with: rm * .o I was puzzled by the message ".o: No such file", and then understood why... Now, I always start with ls and if satisfied of the output, replace ls with rm
- contravariant 5y agoQuite a lot of SQL dialects allow the syntax "DELETE * FROM X" for this exact reason, allowing you to more easily change a select statement into a delete.
- rossvor 5y agoThe above solution unfortunately doesn't work for those of us who use fzf (or other fuzzy runners), since that RUN_SCARY_THINGY=yes var will be part of the matched line which you will run inadvertently in your coffee-deprived mind. I rarely make mistakes while consciously typing out commands, but running commands with wrong arguments because I didn't pay enough attention on the matched line does happen semi-regularly. Doesn't help that since doing stuff with fzf is much faster than typing out full commands, that your brain sometimes just doesn't have enough time to ask -- wait, should I be running this right now?