shell 脚本 if 语句中的 -t 标志是什么意思?
What does the -t flag mean in a shell script if statement?
我不确定 -t 标志对 unix shell 脚本意味着什么,因为我在网上找不到任何提及它的地方。
我 运行 进入 bash shell shell 脚本的 if 语句。我已经包含了经过清理的代码段:
source "${BASH_SOURCE%/*}"/some_script
if [[ ! -t 0 ]] && [[ $(id -u) == 0 ]]; then
echo 'got here'
else
echo 'no get here'
fi
我不明白测试命令中的“-t”标志是什么。我认为它与测试文件没有任何关系,因为它没有出现在我发现的其他文件测试标志中,并且因为 0 不是文件。
提前致谢。
-t
表示:
True if file descriptor is open and refers to a terminal.
在这种情况下,文件描述符 0 是标准输入,因此它正在检查标准输入是否来自终端。
有关这些文件描述符的完整列表,运行 man bash
并搜索“条件表达式”。
我不确定 -t 标志对 unix shell 脚本意味着什么,因为我在网上找不到任何提及它的地方。
我 运行 进入 bash shell shell 脚本的 if 语句。我已经包含了经过清理的代码段:
source "${BASH_SOURCE%/*}"/some_script
if [[ ! -t 0 ]] && [[ $(id -u) == 0 ]]; then
echo 'got here'
else
echo 'no get here'
fi
我不明白测试命令中的“-t”标志是什么。我认为它与测试文件没有任何关系,因为它没有出现在我发现的其他文件测试标志中,并且因为 0 不是文件。
提前致谢。
-t
表示:
True if file descriptor is open and refers to a terminal.
在这种情况下,文件描述符 0 是标准输入,因此它正在检查标准输入是否来自终端。
有关这些文件描述符的完整列表,运行 man bash
并搜索“条件表达式”。