bash – SH条件重定向
发布时间:2020-12-15 18:29:50 所属栏目:安全 来源:网络整理
导读:我希望能够根据命令行开关将我脚本的某些输出重定向到/ dev / null. 我不知道该怎么做. 以愚蠢的方式,它会是这样的(以一种过于简化的方式): #!/bin/shREDIRECT=if [ $# -ge 1 -a "$1" = "--verbose" ]; then echo "Verbose mode." REDIRECT='12 /dev/null'f
我希望能够根据命令行开关将我脚本的某些输出重定向到/ 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特定的.这只是很久以前的记忆. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容