I want to be able to specify the redirection command/options via a variable (that I might set based on certain conditions, etc.). But when I run this bash script for example :
REDIRECT=">>test"
exec echo hi ${REDIRECT}
I get (via bash -x output) :
+ REDIRECT='>>test'
+ exec echo hi '>>test'
hi >>test
It looks like exec is placing the value of REDIRECT variable inside single quotes, instead of literally substituting its value.
How can I fix/get around this?
outfile
variable andexec echo hi >>$outfile
, or do you sometimes want to append and sometimes not?