In sh programming I can do:
dryrun="echo " ./myscript.sh
${dryrun}ls -l (as an example)
An easy solution is to use the env
command:
env dryrun=echo ./myscript.sh
This will work with pretty much any shell. The env
command takes a list of var=value
pairs and adds them to the environment of whatever command is at the end of the list. See man env
for more information.