如何来表示一个命令行参数是可选打印时使用 [英] How to denote that a command line argument is optional when printing usage

查看:141
本文介绍了如何来表示一个命令行参数是可选打印时使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我可以在以下任一方式运行的脚本。

Assume that I have a script that can be run in either of the following ways.

./foo arg1 arg2
./foo

有表示打印命令的正确用法时ARG1 ARG2和不是强制性的争论一个被普遍接受的方式?

Is there a generally accepted way to denote that arg1 and arg2 aren't mandatory arguments when printing the correct usage of the command?

我有时发现使用印有包裹在如以下使用打印输出括号中的参数。

I've sometimes noticed usage printed with the arguments wrapped in brackets like in the following usage printout.

Usage: ./foo [arg1] [arg2]

难道这些括号表示参数是可选的,或者是有其他表示,一个参数是可选的普遍接受的方式是什么?

Do these brackets mean that the argument is optional or is there another generally accepted way to denote that an argument is optional?

推荐答案

我个人还没有看到一个'标准',它表示一个选项是可选的(怎么样有一个标准,它定义语言如何一定例如写),因为它确实是个人的选择,而是根据<一个href=\"http://pic.dhe.ibm.com/infocenter/iisinfsv/v8r5/topic/com.ibm.swg.im.iis.common.doc/common/command_conventions.html\">IBM's文档和维基,与众多的shell脚本一起,我亲眼看到(和命令行选项从不同的程序)的事实上的是治疗方括号( [] )参数可选参数。从Linux的例子:

I personally have not seen a 'standard' that denotes that a switch is optional (like how there's a standard that defines how certain languages are written for example), as it really is personal choice, but according to IBM's docs and the Wiki, along with numerous shell scripts I've personally seen (and command line options from various programs) the 'defacto' is to treat square bracketed ([]) parameters as optional parameters. Example from Linux:

(输出修剪...)

usage: ping [-c count] [-t ttl] host

其中, [ - ç计数] [ - T的TTL] 是可选参数,但主机不是

我个人按照事实上的以及通过使用 [] 来表示可选参数。

I personally follow the defacto as well by using [] to mean optional parameter.

这篇关于如何来表示一个命令行参数是可选打印时使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆