I often interactively loop over e.g. my files and want to perform a specific operation on all of them, let\'s say I\'d like to rename all files:
for file in
There is no option for "dry run" as explained by devnull but there is a simple workaround:
debug=
#debug=echo
$debug mv "$file" "${file}_new"
If you remove the comment from the second assignment (without changing anything else), you enable "dry run" for the dangerous mv command.
A more elaborate approach would be to check some condition (like a command line option):
debug=
if [[ ...enable dry run?... ]]; then
debug=echo
fi
Note: The empty assignment is only necessary when you have the option -u ("Treat unset variables as an error when substituting.") enabled.
Important: This won't work well, when your commands use redirections (because the shell will always do them before the command is even started).