I am trying to use command substitution in a bash script to output redirection symbols based on a variable like so:
IS_VERBOSE=false curl $BLAH $( $IS_VERBOSE && echo '-i' || echo '> /dev/null' )
That is, if verbose, add the
-i switch, otherwise, throw everything from stdout away. The problem is that when
IS_VERBOSE is false, my command becomes
curl $BLAH \> /dev/null
More generally, command substitution escapes the characters
> >> & | # $ and possibly others. How can I output these symbols without escaping using command substitution?