我希望能够/dev/null
根据命令行开关将脚本的某些输出重定向到。我不知道我该怎么做。
以一种愚蠢的方式,它会是这样的(以一种过于简化的方式):
#!/bin/sh
REDIRECT=
if [ $# -ge 1 -a "$1" = "--verbose" ]; then
echo "Verbose mode."
REDIRECT='1>&2 > /dev/null'
fi
echo "Things I want to see regardless of my verbose switch."
#... Other things...
# This command and others along the script should only be seen if I am in verbose mode.
ls -l $REDIRECT
Run Code Online (Sandbox Code Playgroud)
请问有什么线索吗?
谢谢人们。