小编j4x*_*j4x的帖子

SH 条件重定向

我希望能够/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)

请问有什么线索吗?

谢谢人们。

bash redirection sh

3
推荐指数
1
解决办法
1312
查看次数

标签 统计

bash ×1

redirection ×1

sh ×1