Command line and syntax format of calling command

Time:2021-9-20

concept

shell1

shell(shell) is a command line interface (CLI) program that can receive commands entered by the keyboard and pass them to the operating system for execution. Today, in addition to the command-line interface (such as shell), we also have a graphical user interface (GUI).

On most Linux systems,BashIs the default shell program.

On older Windows systems,CMD.EXEIs the default shell program. In the latest version of windows 10 system,PowerShellIt has become its default shell program, but cmd.exe remains in it.

Terminal simulator

Terminal emulator can be referred to as terminal in most cases. It is a window program that allows you to interact with the shell. Developed and open source by MicrosoftWindows TerminalIs one of them.

Command line and syntax format of calling command

Basic syntax of commands

Taking PowerShell as an example, this paper discusses the basic syntax format of calling shell commands.
In PowerShell, type after the command -?Parameter and enter, you will get the basic usage of this command. For example, we entercopy -?When, you will get the following prompt:

PS C:\Users\hookin> copy -?

name
    Copy-Item

grammar
    Copy-Item [-Path] <string[]> [[-Destination] <string>]  [<Com
    monParameters>]

    Copy-Item [[-Destination] <string>]  [<CommonParameters>]


alias
    cpi
    cp
    copy


remarks
    Get help could not find the help file for the cmdlet on this computer. It shows only part
    help.
        --To download and install the help file for the module that contains this cmdlet, use the U
    pdate-Help。
        --To view the help topic for this cmdlet online, type: "get help"
    Py item - online "or
           Go to https://go.microsoft.com/fwlink/?LinkID=113292 。

go tohttps://go.microsoft.com/fwli…View online help.

You can see the full name of this commandCopy-Item, we used its aliascopy

such as[-xxx]<xxx[]>The meaning is as follows:

  • [-xxx]

    Optional parameters, which can be omitted and not written,-xxxIs a parameter, with left and right square brackets[and]Package indicates optional, for example:

    copy *.txt child
    copy -Path *.txt -Destination child

The effect of executing these two commands is the same.

If explicitly declared-PathOr / and-DestinationParameter, the position of the explicitly declared parameter can be changed:

copy -Destination child -Path *.txt
copy -Destination child *.txt
copy child -Path *.txt

PowerShell will recognize the position of the value and determine which parameter it corresponds to (how to judge will be described below).

  • <xxx>

    Required value, such as[-Path] <string[]>express-PathThe parameter is writable or not, but the value after itstring[](represents a string array, which will be described below) must be written.

    Another example[[-Destination] <string>]express-DestinationAnd its valuestringThe composition of the whole is optional, but if you want to use this parameter, you can write it directlystringcharacter string.

data type

PowerShell supports many data types, includingstring int64 SwitchParameterWait, you can read the online help when you encounter it.

  • string

    String type. Double quotation marks can be omitted without writing.

    copy -Path *.txt -Destination child
  • string[]

    String array. The above code can be written as follows:

    copy -Path 1.txt,2.txt -Destination child

That is, the elements in the array are separated by commas,separate.

  • SwitchParameter

    Switch parameters, equivalent toBooleanBoolean, when typedtrue, default when not typed.

    PS E:\Temp\dosTest> copy -Path 1.txt,2.txt -Destination child -Confirm
    
    confirm
    Are you sure you want to perform this operation?
    Performing action copy file on target item: e: \ temp \ dostest \ 1.txt target: e: \ temp \ dostest \ child \ 1.txt.
    [Y] Yes [a] Yes to all [n] no [l] no to all [S] pause (s) [?] help (default is "Y"): y
    
    confirm
    Are you sure you want to perform this operation?
    Performing action copy file on target item: e: \ temp \ dostest \ 2.txt target: e: \ temp \ dostest \ child \ 2.txt.
    [Y] Yes [a] Yes to all [n] no [l] no to all [S] pause (s) [?] help (default is "Y"): y

In the above command, you typed a command that is not given in the local help-ConfirmParameters, according toCopy item online helpDescription of:

-Confirm

Prompts you for confirmation before running the cmdlet.

Prompt you for confirmation before running the cmdlet.

attribute value
Type: Switchparameter switch parameter
Aliases: CF, i.e-ConfirmEquivalent to-cf
Position: Named requires active declaration
Default value: False error
Accept pipeline input: False error

You can see that its default value isfalse, typetrue, but you can also take the initiative to declarefalseortrue

copy -Path 1.txt,2.txt -Destination child -Confirm:$false
copy -Path 1.txt,2.txt -Destination child -Confirm:$true

Position

Let’s have a lookcopyIntroduction to several parameters of:

-Path

Specifies, as a string array, the path to the items to copy. Wildcard characters are permitted.

Specifies the path of the item to copy as a string array. Wildcards are allowed.

attribute value
Type: String[]
Position: 0
Default value: None
Accept pipeline input: True
Accept wildcard characters: True

-Destination

Specifies the path to the new location. The default is the current directory.

Specifies the path to the new location, which defaults to the working directory.

To rename the item being copied, specify a new name in the value of the Destination parameter.

To rename the item being copied, specify a new name in the value of the destination parameter.

attribute value
Type: String
Position: 1
Default value: Current directory
Accept pipeline input: True
Accept wildcard characters: False

Compare these parameters:

parameter Position value
-Confirm Named
-Path 0
-Destination 1

-ConfirmThe position of isNamed, indicating that its value can only be modified after declaration; The position value of other parameters is01, indicating the order of reading.

PowerShell is pre configuredPositionTo determine which optional parameter the parameter value corresponds to.

copy -Destination child *.txt
#*. TXT is the value of - path

copy child -Path *.txt
#Child is the value of - destination

copy *.txt child
#*. TXT is the value of - path,child 是 -Destination 的值

copy -Path 1.txt,2.txt -Destination child
#- confirm is the default value false

copy -Path 1.txt,2.txt -Destination child -Confirm
#- confirm is true

  1. What is “the Shell”?(http://linuxcommand.org/lc3_l…