Linux shell command help format detailed explanation

Time:2021-2-21

preface

The Linux shell command can be used to-hor--helpTo print help notes, or throughmanSometimes we write simple help instructions for our own programs. In fact, the format of help instructions is regular

Help example

Here’s what’s going ongit resetCommand, through theman git-resetCan view


git reset [-q] [<tree-ish>] [--] <paths>...
git reset (--patch | -p) [<tree-ish>] [--] [<paths>...]
git reset [--soft | --mixed | --hard | --merge | --keep] [-q] [<commit>]

There are several types of commands and parameters

  • No modifier parameters: native parameters
  • < >: occupancy parameter
  • []: optional combination
  • (): required combination
  • |: mutex parameter
  • …: the previous parameter can be specified repeatedly
  • –: Mark subsequent parameter types

Let’s introduce them one by one

Interpretation of parameter types

Native parameter

The characters in the instruction document are the characters that the command needs to use, such as the characters of the above commands


git reset

This parameter must be specified when using, and it is consistent with the description document

Occupancy parameter

Expression:<>

Similar to the native parameters, they are all required to be specified, except that the actual characters of the space occupying parameters are specified when they are used. At the same time, for the convenience of reading, they are represented by a description vocabulary and expressed in<>Surround, for example


<paths>

Represents a path. When used, it can be specified as a specific path, andpathsIt’s just a description. Some help descriptions also use uppercase to represent the space occupying parameters. For example, write the above parameter description asPATHS

Optional combination

Expression:[]

The parameters in brackets are optional, such asusageThe second one is inside[-q] , then-qIs an optional parameter

Optional and space occupying parameters can also be used at the same time, such as


[<commit>]

Indicates that the parameter can specify a submission or not

Required combination

Expression:()

Parameters in brackets must be specified. Usually, there are some mutually exclusive parameters, such as


(--patch | -p)

express--patchand-pYou must specify one of these two parameters

Mutually exclusive parameters

Expression: |

Mutex parameters are generally in the()and[]For example


[--mixed | --soft | --hard | --merge | --keep]

Repeat parameter

Expression: ...

Indicates that the previous parameter can be specified more than one, such as


<paths>...

<paths>Is a space occupying parameter, which must be specified as path,… And indicates that multiple paths can be specified. A typical use scenario of repeating parameters is to move files to a directory, such as the following command


git mv [<options>] <source>... <destination>

We can use it like this


git mv -f a.cpp b.py dir

In this case, options corresponds to-fParameter, source corresponds toa.cpp b.py, destination corresponds todir

Mark subsequent parameter types

Expression:--

Represents a type of subsequent parameter. For example, if you use the following command


git reset -p -- xx

Compared with the first command, XX here should be<paths>Parameter, when we specify--After that, GIT will think that XX is a path, even if it is a special symbol or the path does not exist. This is a common way of shell command. For example, we have a file named-h, if you want to delete this file, execute


rm -h

It can’t be deleted because – h will be considered as a parameter option of RM and should be used


rm -- -h

The shell will-hInterpreted as a file name passed tormcommand

Interpretation of actual combat

Finally, to explain a more complex help


git cat-file (-t [--allow-unknown-type]|-s [--allow-unknown-type]|-e|-p|<type>|--textconv) <object>

The command parameter consists of four parts, among whichgitandcat-fileIs the native parameter,()It’s an optional combination,<object>Is the occupancy parameter

The combination consists of six parts, which are mutually exclusive


-t [--allow-unknown-type]
-s [--allow-unknown-type]
-e
-p
<type>
--textconv

Therefore, the help description of the command can be split as follows


git cat-file -t <object>
git cat-file -t --allow-unknown-type <object>
git cat-file -s <object>
git cat-file -s --allow-unknown-type <object>
git cat-file -e <object>
git cat-file -p <object>
git cat-file <type> <object>
git cat-file --textconv <object>

summary

The above is the whole content of this article, I hope the content of this article can bring some help to your study or work, if you have any questions, you can leave a message to exchange.

Recommended Today

Background management system menu management module

1 menu management page design 1.1 business design Menu management, also known as resource management, is the external manifestation of system resources. This module is mainly to add, modify, query and delete the menu. CREATE TABLE `sys_menus` ( `id` int(11) NOT NULL AUTO_INCREMENT, `Name ` varchar (50) default null comment ‘resource name’, `URL ` varchar […]