I'm trying to add a debug option to a script of mine. Normally I want to hide any output, like warnings etc, so I put >/dev/null 2>&1
behind a lot of commands.
Now, when I want to debug my script, I would have to manually remove those, or put every command inside an if ... fi
testing for a $DEBUG
Variable.
I thought putting >/dev/null 2>&1
inside a Variable ($REDIR
) and writing command arg1 $REDIR
would do the trick. If I want to debug, I would only need to leave $REDIR
empty.
But a short test on my shell showed me, that it won't work that way:
~$ echo "bla" >/dev/null 2>&1
~$ REDIR=>/dev/null 2>&1
~$ echo "bla" $REDIR
bla
~$
Using "
or '
around >/dev/null 2>&1
didn't work either for obvious reasons.
So why does my idea not work here? Did I misunderstand something about putting commands etc. into Variables and calling them?