3 ms·
Why not simply DRYRUN=echo cmd() { $DRYRUN "$@" } ?
by tremon 5y ago
Why not simply
DRYRUN=echo
cmd() {
$DRYRUN "$@"
}
?
- mr-wendel 5y agoThe printf version will give you automatic quoting making copy'n'paste really easy to test. It' also mixes well w/ a verbose option for "--verbose" or such.
- ebeip90 5y agoFor those using zsh, you can get better quoting (and only when necessary, and handles non-printable characters and newlines better) than using printf. run() { if dry; then echo "${(q-)@}" else "$@" fi }
- croehrig 5y agoI use this all the time (I call it $EXEC instead), and have gotten into the habit of starting all my scripts with EXEC=echo and put it on every command that does any file changes. It has saved my bacon many times. It doesn't work all the time as the previous poster noted, but it is very low friction which is especially important when writing quick throw-away scripts.