I'm writing a pretty ad-hoc install script for some thing. No much control constructs, basically just a list of commands. I'd like the user to confirm each command before it gets executed. Is there a way to let bash do that, without prefixing every command with a shell function name?
Bash – Prompt for confirmation for every command
bashinteractivepromptshell-script
Best Answer
You could use
extdebug
:For reference, the
zsh
equivalent would be:More portably:
Beware that in
cmd3 > file
, thefile
will be truncated even if you sayn
. So you may want to write it:Or move the
eval
to therun
function as in:Another portable one, but with even more limitations:
It only works for commands (ones found in
$PATH
), and arguments can only be strings (no variable or any shell structure, though xargs understand some forms of quoting), and you can't have redirections, pipes...