我希望能够根据命令行开关将我脚本的某些输出重定向到/ 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
请问有什么线索吗?
谢谢大家.
如果处于详细模式,请将STDOUT绑定到另一个句柄,否则将这些句柄链接到/ dev / null.然后编写脚本,以便可选的东西指向额外的句柄.
#!/bin/sh exec 6>/dev/null if [ $# -ge 1 -a "$1" = "--verbose" ]; then echo "Verbose mode." exec 6>&1 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 >&6 2>&1
这应该让你开始.我不确定这是否是BASH特定的.这只是很久以前的记忆.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。