I have many commands in a bash script that have >/dev/null 2>&1 used to redirect stdout and stderr to /dev/null.
Let us say I have a variable called echoOn, which can be either 0 or 1.
If echoOn is equal to 0, then I wish to keep the redirections on the commands in the script. If it is equal to 1, then I do not want the redirection in place, so the commands are able to output.
I do not wish to suppress the output of all commands but only specific ones within the script.
Is there a more abstract way for me to do this without manually adding if statements to every command in question?
I am open to having a function in which I pass the command and its arguments and replacing each command with a call to the aforementioned function and the command to be executed.
case "$echoOn" in 0) exec {myout}>/dev/null {myerr}>&$myout ;; 1) exec {myout}>&1 {myerr}>&2 ;; esac ; echo stuff 1>&$myout 2>&$myerr/dev/nullwhen you want to suppress output and to/dev/stdoutwhen you don't?