如何解释 bash 命令的“用法”语法?

rao*_*son 11 usage syntax

例如,在 bash 中,您究竟必须如何解释命令“使用”输出的输出。

例如,在我的 OS X 上,cp给了我

usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file
       cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... target_directory
Run Code Online (Sandbox Code Playgroud)
  • 嵌套选项(例如 -R 中的 -H)表示什么?
  • 大写和小写有什么意义吗?
  • 什么时候参数是可选的、必需的?

我需要针对我的程序实施 telnet 命令行,我想弄清楚这一点。

Jus*_*tin 15

对于任何试图了解使用输出意味着什么的人来说,最好的方法是man man.

认真 :-) 花时间学习这些约定,它真的很有帮助。

   The following conventions apply to the SYNOPSIS section and can be used
   as a guide in other sections.

   bold text          type exactly as shown.
   italic text        replace with appropriate argument.
   [-abc]             any or all arguments within [ ] are optional.
   -a|-b              options delimited by | cannot be used together.
   argument ...       argument is repeatable.
   [expression] ...   entire expression within [ ] is repeatable.
Run Code Online (Sandbox Code Playgroud)


Ins*_*yte 2

首先,虽然有一般约定,但它们并没有统一应用。

  • 在这种情况下,它表示如果您使用-R(表示“递归”),那么您可以使用-H-L-P。如果您不使用-R,则这些选项不相关。
  • 是的,案例几乎总是很重要。所以通常-h-H做完全不同的事情。
  • 方括号通常表示选项或参数是“可选的”。(前面有连字符的词是“选项”,没有连字符的词是参数。)如果没有括号,选项或参数通常是必需的。在您的示例中,“source_file”和“target_directory”都是必需的。“...”表示前面的参数可以重复。

其他值得注意的点:

  • 竖线表示“OR”。So[-fi | -n]表示您可以使用-fand/or-i但不能与 组合使用-n
  • 括号中的分组选项表示您可以使用其中任何一个。因此[-apvX]表示您可以使用这些选项的任意组合。他们甚至不需要被粉碎在一起。所以这-a -v -p将是一个有效的组合。