Something like: ./dangerous-script.sh $args | bash
The following prefix in a ps1 script enables the -WhatIf and -Confirm parameters:
[CmdletBinding(SupportsShouldProcess=$true)]
To enable -Confirm by default for scary scripts, just use: [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='High')]
The nice thing is that in PowerShell, unlike bash, this flows through to the vast majority of other commands. If the script has the snippet above, then you don't have to litter it with "if ( $userSaidYes ) { ... }" blocks all over the place.Similarly, PowerShell automatically wires up logic to produce all of the useful modes you might want:
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend
This is very fiddly to implement manually, and "Suspend" is likely impossible for most shells.See: https://docs.microsoft.com/en-us/powershell/scripting/learn/...
# rm -rf some_dir
Then if you accidentally press return before completing it hasn't happened.
When you have reviewed and are sure it is correct, you recall and delete the hash to execute - simples!
I mean, I use the # hack sometimes too, but when I don't, I find myself often being afraid of accidentally coming on the enter key.
"Run it as a query first" gets 90% of the way until you drop a constraint by accident whilst rewriting it as an update :o
If it is Postgres (don't know about other dbs), you can go a way long way using "savepoints" and "rollbacks" to truly have a trial-and-error safe surgery on db. Still dangerous, but quite helpful. I hate working on any other db without those features. Postgres also allows schema changes to be within a txn envelope.
You can jam a select in the end of the transaction to check what happens.
https://dev.mysql.com/doc/refman/8.0/en/mysql-command-option...
alias harikb_script='harikb_script --do-it'
in their .bashrc to eliminate this annoying step. my_command() {
command my_command "$@" --do-it
}$ run-script.sh --dry run
`--dry-run` parameter not recognized
Executing ...