How to denote that a command line argument is optional when printing usage

后端 未结 3 1521
情书的邮戳
情书的邮戳 2021-01-30 02:18

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

./foo arg1 arg2
./foo

Is there a generally accepted way to denote

3条回答
  •  独厮守ぢ
    2021-01-30 02:56

    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:

    ping (output trimmed...)

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

    where [-c count] and [-t ttl] are optional parameters but host is not.

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

提交回复
热议问题