加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – ‘ – ‘如果代表stdin有特定的名字吗?

发布时间:2020-12-15 22:38:50 所属栏目:安全 来源:网络整理
导读:在几个命令行应用程序中,如果将stdin管道输入到它们中,则需要提供 – 字符而不是输入文件. 样品: $foo | bar - 现在我想知道:这个 – 字符在这种情况下使用时是否具有正式的特殊名称,例如:虚线stdin运算符或类似的东西?如果是这样,哪一个? 我的问题的背
在几个命令行应用程序中,如果将stdin管道输入到它们中,则需要提供 – 字符而不是输入文件.

样品:

$foo | bar -

现在我想知道:这个 – 字符在这种情况下使用时是否具有正式的特殊名称,例如:虚线stdin运算符或类似的东西?如果是这样,哪一个?

我的问题的背景是我想编写一个检测这个字符的函数,然后相应地处理stdin,而不是将参数解析为数组,我想知道该函数调用什么.

解决方法

POSIX标准对此字符的用法不使用任何特殊名称.它说:

For utilities that use operands to represent files to be opened for either reading or writing,the ‘-‘ operand should be used to mean only standard input (or standard output when it is clear from context that an output file is being specified) or a file named -.

然后

Where a utility described in the Shell and Utilities volume of POSIX.1-2008 as conforming to these guidelines is required to accept,or not to accept,the operand ‘-‘ to mean standard input or output,this usage is explained in the OPERANDS section. Otherwise,if such a utility uses operands to represent files,it is implementation-defined whether the operand ‘-‘ stands for standard input (or standard output),or for a file named -.

手动页面似乎也没有使用任何特殊名称:

If no files are specified,or if the file “-” is given,grep searches standard input.

所以看来你必须发明自己的名字.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读