我正在为GNU/Linux上的命令行工具寻找某种“语法键”,类似于Microsoft的以下文档:
例如,在Microsoft命令行语法文档中使用方括号中的文本来表示可选项。方括号中的文本是一组必需的项,您必须选择其中一项。以此类推。
在GNU/Linux中,用于指示命令行语法的符号是什么,每个符号意味着什么?
发布于 2019-09-25 09:47:04
以下是man 7 man-pages的摘录,它描述了手册页中各节的常规含义:
SYNOPSIS A brief summary of the command or function's interface.
For commands, this shows the syntax of the command and
its arguments (including options); boldface is used for
as-is text and italics are used to indicate replaceable
arguments. Brackets ([]) surround optional arguments,
vertical bars (|) separate choices, and ellipses (...)
can be repeated.我要补充的是,“黑体字”和“斜体”究竟是如何出现在你的终端上是一个不同的问题。在我的终端上,我会用粗体表示替换参数的as-is文本和带下划线的文本;在某些终端上,您可能根本得不到任何这样的格式设置。
主旨是:
总的来说,这些约定实际上与您引用的Microsoft文档非常相似。
下面是git diff手册页中的一个示例概要:
SYNOPSIS
git diff [options] [<commit>] [--] [<path>...]
git diff [options] --cached [<commit>] [--] [<path>...]
git diff [options] <commit> <commit> [--] [<path>...]
git diff [options] <blob> <blob>
git diff [options] [--no-index] [--] <path> <path>可能的选项如此之多,以至于手册的作者决定不把它们全部列在概要中,而只是说[options]。
概要中的多行是因为有多种可能的(相互排斥的)方法来使用这个特定的命令。
方括号中的所有内容都是可选的,尖括号中的所有内容都是占位符。
(注:提交和blob是可以存储在Git中的对象类型;blob代表文件的内容,commit代表Git跟踪的整个文件集的状态。与你的问题无关,但我提到这一点是为了避免术语上的一个谜。)
另一个例子,grep命令的概要说明了另一个惯例:用所有大写写的单词有时用于显示占位符(如上面git手册页中的尖括号)。
SYNOPSIS
grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] -e PATTERN ... [FILE...]
grep [OPTIONS] -f FILE ... [FILE...]在这里,同样,有三种不同的方法来调用grep命令。通过阅读上面的内容,您可以看到:
grep apple orange pear...means,apple是模式,orange和pear都是文件名。
同样,您可以在以下内容中看到这一点:
grep -e apple -e orange pear grapefruitapple和orange都是模式,pear和grapefruit都是文件。
至于这意味着在给定模式和文件时命令将做什么,您必须阅读手册页的更多内容,而不仅仅是概要。但是,这个概要允许您确定您要给出的命令将如何解释各种参数。
但是,没有关于大纲符号的绝对规则。以下是sed的概要:
SYNOPSIS
sed [OPTION]... {script-only-if-no-other-script} [input-file]...要完全理解这一点,您需要在手册页中进一步阅读,您会发现:
If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.发布于 2019-09-25 09:48:24
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. Exact rendering may vary depending on the output device. For instance, man will usually not be able to render italics when running in a termi‐ nal, and will typically use underlined or coloured text instead. The command or function illustration is a pattern that should match all possible invocations. In some cases it is advisable to illustrate sev‐ eral exclusive invocations as is shown in the SYNOPSIS section of this manual page.
发布于 2019-09-16 08:32:20
我不知道你到底想要什么。我举三个例子来说明你是对的:
Pipelines
A pipeline is a sequence of one or more commands separated by
one of thwe control operators | or |&. The format for a pipeline is:
[time [-p]] [ ! ] command [ [|||&] command2 ... ](来自Bash手册;在shell中键入man bash )
在来自GNU的bash.pdf中,包含一些微妙的更改:
The format for a pipeline is
[time [-p]] [!]command1[ | or |&command2] ...在posix规范中:
The format for a pipeline is:
[!] command1 [ | command2 ...]shell本身就使用了如此多的特殊字符,因此一致的元语法是不切实际的。但他们都用同样的嫌疑犯。
"shell“不是”命令行“,GNU/Linux不是MS,所以差异加起来。您可能首先需要一些关于使用linux和unix的基本信息--当然,web上确实有适合您的情况的信息。GNU/Linux并不认为有责任向windows解释基本的或不同的内容。
另一个示例,使用find命令/实用程序
man find在GNU/Linux bash中给出了如下内容:
find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] [ex-
pression]当您在男子寻呼机中输入/EXPR (或只需继续阅读和滚动)时,您将到达
EXPRESSION
The part of the command line after the list of starting points is the
expression. This is a kind of query specification ...[cut]这就需要你:
OPERATORS
Listed in order of decreasing precedence:
( expr )
Force precedence. Since parentheses are special to the shell,
you will normally need to quote them. Many of the examples in
this manual page use backslashes for this purpose: `\(...\)' in-
stead of `(...)'.所有这些都会导致一个复杂的小“查询”,比如:
find -L /students/projects/myname \
-type d '(' -name '.aaa' -o -name '*rc*' ')' -prune -o \
-path '*/*/class_project/*/*/pikachu/*/*/bambi/bambi.txt' -print它搜索某些子文件夹中的所有"bambi.txt“,跳过其他特定的subfolders...it需要()来表示:”剪枝(跳过),如果它是一个文件夹,并且名称是.aaa或包含rc“。
然后,通过使用单引号或反斜杠,需要保护父本不受shell解释的影响。大多数情况下,-o for OR和默认-a用于AND就足够了,所以GNU/Linux也可以使用它。
https://unix.stackexchange.com/questions/541872
复制相似问题