gpt4 book ai didi

shell - wget:这个尾随的破折号代表/做什么?

转载 作者:行者123 更新时间:2023-12-04 16:59:11 28 4
gpt4 key购买 nike

wget http://ipinfo.io/ip -qO -
我是新来的 bash并且似乎无法弄清楚尾随的破折号有什么作用(或者为什么在这个命令中需要它)。

任何帮助深表感谢。

最佳答案

按照惯例(并非所有程序都遵循),文件名位置中的破折号是指适当的标准输入或标准输出。因为这是对 -O 的一个论点(输出),它指的是标准输出。

一种更详细的编写方式(在 Linux 或其他操作系统上,/dev/stdout 可用于除 shell 之外的程序)是:

wget http://ipinfo.io/ip --quiet --output-document=/dev/stdout

碰巧的是,这种行为是由 POSIX Utility Syntax Guidelines 定义的。 .具体来说:

Guideline 5: One or more options without option-arguments, followed by at most one option that takes an option-argument, should be accepted when grouped behind one '-' delimiter.



...因此, -qO-q -O 的处理方式相同.

Guideline 13: 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 -.



...因此,关于 - 的行为是明确规定的。

关于shell - wget:这个尾随的破折号代表/做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34005959/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com