如果语句说明,则-t标志在shell脚本中是什么意思?

发布于 2025-01-24 10:00:07 字数 357 浏览 2 评论 0原文

我不确定-t标志对Unix Shell脚本的含义是什么,因为我在网上找不到任何提及。

我遇到了一个if语句,以获取bash shell shell脚本。我包括了一个消毒的片段:

source "${BASH_SOURCE%/*}"/some_script

if [[ ! -t 0 ]] && [[ $(id -u) == 0 ]]; then
    echo 'got here'
else
    echo 'no get here'
fi

我不明白测试命令中的“ -t”标志。我认为它与测试文件没有任何关系,因为它与我发现的其他文件测试标志没有出现,并且因为0不是文件。

提前致谢。

I'm not sure what the -t flag means for unix shell scripts since I can't find any mention of it online.

I ran into an if statement for a bash shell shell script. I've included a sanitized snippet:

source "${BASH_SOURCE%/*}"/some_script

if [[ ! -t 0 ]] && [[ $(id -u) == 0 ]]; then
    echo 'got here'
else
    echo 'no get here'
fi

I don't understand what the "-t" flag in the test command. I assume it doesn't have anything to do with testing files since it didn't appear with the other file testing flags I found and because 0 is not a file.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

轻许诺言 2025-01-31 10:00:07

-t表示:

True if file descriptor is open and refers to a terminal.

在这种情况下,文件描述符0是标准输入,因此检查标准输入是否来自终端。

有关这些文件描述符的完整列表,请运行MAN BASH并搜索“条件表达式”。

-t means:

True if file descriptor is open and refers to a terminal.

In this case, file descriptor 0 is standard input, so it's checking to see if standard input is coming from the terminals.

For a complete list of these file descriptors, run man bash and search for "CONDITIONAL EXPRESSIONS".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文