How do I conditionally redirect the output of a command to /dev/null?
Posted
by Lawrence Johnston
on Stack Overflow
See other posts from Stack Overflow
or by Lawrence Johnston
Published on 2010-03-25T23:11:17Z
Indexed on
2010/03/25
23:13 UTC
Read the original article
Hit count: 175
I have a script. I would like to give this script a quiet mode and a verbose mode.
This is the equivalent of:
if $verbose
then
redirect="> /dev/null"
fi
echo "Verbose mode enabled" $redirect # This doesn't work because the redirect isn't evaluated.
I'd really like a better way of doing this than writing if-elses for every statement affected.
eval could work, but has obvious side effects on other variables.
© Stack Overflow or respective owner