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

标签 shell wget

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/

相关文章:

bash - 复制变量的值而不是引用 bash 脚本

linux - wget 下载新的通配 rune 件并覆盖旧的

html - 如何将 "complete"HTML 文件保存为单个文件?

linux - tcsh 脚本中设置的环境变量不适用于 bash 脚本

bash - 如何在 POSIX shell 中测试命令输出是否为非空?

c - 如何将系统(命令)输出打印到文件C?

ssl - 您如何获得受 shibboleth 身份验证保护的页面?

linux - 如何使用 sed 将文件中的字符串替换为 shell 变量

linux - wget - "No route to host"运行armbian 的设备和android 热点之间的连接

perl - 我的 ETrade OAuth 获取 token 请求有什么问题?