首页 > 解决方案 > 这些重定向在 Bash 中的含义是什么:“8>&1”、“9>&2”和“1>&9”?

问题描述

我之前2>&1在 Bash 中遇到过语法,从这个问题中我了解到这意味着将 stderr 的输出重定向到 stdout。但是,我也遇到了标题中的语法,在 StackOverflow 或 Google 上找不到任何关于它们的含义。

它们出现在GitHub 上的这个 Bash 完成脚本中,特别是这个函数:

# Run something, muting output or redirecting it to the debug stream
# depending on the value of _ARC_DEBUG.
__python_argcomplete_run() {
    if [[ -z "$_ARC_DEBUG" ]]; then
        "$@" 8>&1 9>&2 1>/dev/null 2>&1
    else
        "$@" 8>&1 9>&2 1>&9 2>&1
    fi
}

我确信该评论是一个线索,但我不知道 Bash 流有“8”和“9”。我只知道 0 作为标准输入,1 作为标准输出,2 作为标准错误。8 和 9 在 Bash 中是什么意思,这些重定向是什么意思?

标签: bashsyntaxio-redirection

解决方案


推荐阅读