📄 sh.1
字号:
format results in a test for a parameter that is unset or null; omissionof the colon results in a test for a parameter that is only unset..TP${#parameter}String Length. The length in characters ofthe value of parameter..LPThe following four varieties of parameter expansion provide for substringprocessing. In each case, pattern matching notation (see Shell Patterns), ratherthan regular expression notation, is used to evaluate the patterns.If parameter is * or @, the result of the expansion is unspecified.Enclosing the full parameter expansion string in double-quotes does notcause the following four varieties of pattern characters to be quoted,whereas quoting characters within the braces has this effect.(UNIMPLEMENTED IN 4.4alpha).TP${parameter%word}Remove Smallest Suffix Pattern. The wordis expanded to produce a pattern. Theparameter expansion then results inparameter, with the smallest portion of thesuffix matched by the pattern deleted..TP${parameter%%word}Remove Largest Suffix Pattern. The wordis expanded to produce a pattern. Theparameter expansion then results inparameter, with the largest portion of thesuffix matched by the pattern deleted..TP${parameter#word}Remove Smallest Prefix Pattern. The wordis expanded to produce a pattern. Theparameter expansion then results inparameter, with the smallest portion of theprefix matched by the pattern deleted..TP${parameter##word}Remove Largest Prefix Pattern. The wordis expanded to produce a pattern. Theparameter expansion then results inparameter, with the largest portion of theprefix matched by the pattern deleted..LP.sp 2.B Command Substitution.sp.LPCommand substitution allows the output of a command to be substituted inplace of the command name itself. Command substitution occurs whenthe command is enclosed as follows:.nf $(command).fior (``backquoted'' version):.nf `command`.fi.LPThe shell expands the command substitution by executing command in asubshell environment and replacing the command substitutionwith thestandard output of the command, removing sequences of one or more<newline>s at the end of the substitution. (Embedded <newline>s beforethe end of the output are not removed; however, during fieldsplitting, they may be translated into <space>s, depending on the valueof IFS and quoting that is in effect.).sp 2.B Arithmetic Expansion.sp.LPArithmetic expansion provides a mechanism for evaluating an arithmeticexpression and substituting its value. The format for arithmeticexpansion is as follows:.nf $((expression)).fiThe expression is treated as if it were in double-quotes, exceptthat a double-quote inside the expression is not treated specially. Theshell expands all tokens in the expression for parameter expansion,command substitution, and quote removal..LPNext, the shell treats this as an arithmetic expression andsubstitutes the value of the expression..sp 2.B White Space Splitting (Field Splitting).sp.LPAfter parameter expansion, command substitution, andarithmetic expansion the shell scans the results ofexpansions and substitutions that did not occur in double-quotes forfield splitting and multiple fields can result..LPThe shell treats each character of the IFS as a delimiter and usethe delimiters to split the results of parameter expansion and commandsubstitution into fields..sp 2.B Pathname Expansion (File Name Generation).sp.LPUnless the -f flag is set, file name generation is performed after word splitting is complete. Each word isviewed as a series of patterns, separated by slashes. Theprocess of expansion replaces the word with the names ofall existing files whose names can be formed by replacingeach pattern with a string that matches the specified pattern.There are two restrictions on this: first, a pattern cannot match a string containing a slash, and second,a pattern cannot match a string starting with a periodunless the first character of the pattern is a period.The next section describes the patterns used for bothPathname Expansion and the case(1) command..sp 2.B Shell Patterns.sp.LPA pattern consists of normal characters, which match themselves, and meta-characters. The meta-characters are``!'', ``*'', ``?'', and ``[''. These characters losethere special meanings if they are quoted. When commandor variable substitution is performed and the dollar signor back quotes are not double quoted, the value of thevariable or the output of the command is scanned for thesecharacters and they are turned into meta-characters..LPAn asterisk (``*'') matches any string of characters. Aquestion mark matches any single character. A leftbracket (``['') introduces a character class. The end ofthe character class is indicated by a ``]''; if the ``]''is missing then the ``['' matches a ``['' rather thanintroducing a character class. A character class matchesany of the characters between the square brackets. Arange of characters may be specified using a minus sign.The character class may be complemented by making anexclamation point the first character of the characterclass..LPTo include a ``]'' in a character class, make it the firstcharacter listed (after the ``!'', if any). To include aminus sign, make it the first or last character listed.sp 2.B Builtins.sp.LPThis section lists the builtin commands whichare builtin because they need to perform some operationthat can't be performed by a separate process. In addition to these, there are several other commands that maybe builtin for efficiency (e.g. printf(1), echo(1), test(1),etc)..TPalias [ name[=string] ... ]If name=string is specified, the shell defines thealias ``name'' with value ``string''. If just ``name''is specified, the value of the alias ``name'' is printed.With no arguments, the alias builtin prints thenames and values of all defined aliases (see unalias)..TPbg [ job ] ...Continue the specified jobs (or the current job if nojobs are given) in the background..TPcommand command arg...Execute the specified builtin command. (This is useful when you have a shell function with the same nameas a builtin command.).TPcd [ directory ]Switch to the specified directory (default $HOME).If the an entry for CDPATH appears in the environmentof the cd command or the shell variable CDPATH is setand the directory name does not begin with a slash,then the directories listed in CDPATH will besearched for the specified directory. The format ofCDPATH is the same as that of PATH. In an interactive shell, the cd command will print out the name ofthe directory that it actually switched to if this isdifferent from the name that the user gave. Thesemay be different either because the CDPATH mechanismwas used or because a symbolic link was crossed..TP\&. fileThe commands in the specified file are read and executed by the shell..TPeval string...Concatenate all the arguments with spaces. Thenre-parse and execute the command..TPexec [ command arg... ]Unless command is omitted, the shell process isreplaced with the specified program (which must be areal program, not a shell builtin or function). Anyredirections on the exec command are marked as permanent, so that they are not undone when the exec command finishes..TPexit [ exitstatus ]Terminate the shell process. If exitstatus is givenit is used as the exit status of the shell; otherwisethe exit status of the preceding command is used..TPexport name...The specified names are exported so that they willappear in the environment of subsequent commands.The only way to un-export a variable is to unset it.The shell allows the value of a variable to be set at thesame time it is exported by writing.nf export name=value.fiWith no arguments the export command lists the namesof all exported variables..TPfc [-e editor] [first [last]].TPfc -l [-nr] [first [last]].TPfc -s [old=new] [first]The fc builtin lists, or edits and re-executes, commandspreviously entered to an interactive shell..RS +.5i.TP 2-e editorUse the editor named by editor to edit the commands. Theeditor string is a command name, subject to search via thePATH variable. The value in the FCEDIT variableis used as a default when -e is not specified. IfFCEDIT is null or unset, the value of the EDITORvariable is used. If EDITOR is null or unset,ed(1) is used as the editor..TP 2-l (ell)List the commands rather than invokingan editor on them. The commands are written in thesequence indicated by the first and last operands, asaffected by -r, with each command preceded by the commandnumber..TP 2-nSuppress command numbers when listing with -l..TP 2-rReverse the order of the commands listed (with -l) oredited (with neither -l nor -s)..TP 2-sRe-execute the command without invoking an editor..TP 2first.TP 2lastSelect the commands to list or edit. The number ofprevious commands that can be accessed are determinedby the value of the HISTSIZE variable. The value of firstor last or both are one of the following:.TP 2[+]numberA positive number representing a commandnumber; command numbers can be displayedwith the -l option..TP 2-numberA negative decimal number representing thecommand that was executed number ofcommands previously. For example, -1 isthe immediately previous command..TP 2stringA string indicating the most recentlyentered command that begins with thatstring. If the old=new operand is not alsospecified with -s, the string form of thefirst operand cannot contain an embeddedequal sign..TPThe following environment variables affect the execution of fc:.TP 2FCEDITName of the editor to use..TP 2HISTSIZEThe number of previous commands that are accessable..RE.TPfg [ job ]Move the specified job or the current job to theforeground..TPgetopts optstring varThe POSIX getopts command..TPhash -rv command...The shell maintains a hash table which remembers thelocations of commands. With no arguments whatsoever,the hash command prints out the contents of thistable. Entries which have not been looked at sincethe last cd command are marked with an asterisk; itis possible for these entries to be invalid..spWith arguments, the hash command removes the specified commands from the hash table (unless they arefunctions) and then locates them. With the -voption, hash prints the locations of the commands asit finds them. The -r option causes the hash commandto delete all the entries in the hash table exceptfor functions..TPjobid [ job ]Print the process id's of the processes in the job.If the job argument is omitted, use the current job..TPjobsThis command lists out all the background processeswhich are children of the current shell process..TPpwdPrint the current directory. The builtin command maydiffer from the program of the same name because thebuiltin command remembers what the current directoryis rather than recomputing it each time. This makesit faster. However, if the current directory isrenamed, the builtin version of pwd will continue toprint the old name for the directory..TPread [ -p prompt ] [ -e ] variable...The prompt is printed if the -p option is specifiedand the standard input is a terminal. Then a line isread from the standard input. The trailing newlineis deleted from the line and the line is split asdescribed in the section on word splitting above, andthe pieces are assigned to the variables in order.If there are more pieces than variables, the remaining pieces (along with the characters in IFS thatseparated them) are assigned to the last variable.If there are more variables than pieces, the remaining variables are assigned the null string..spThe -e option causes any backslashes in the input tobe treated specially. If a backslash is followed bya newline, the backslash and the newline will bedeleted. If a backslash is followed by any othercharacter, the backslash will be deleted and the following character will be treated as though it werenot in IFS, even if it is..TPreadonly name...The specified names are marked as read only, so thatthey cannot be subsequently modified or unset. The shellallows the value of a variable to be set at the sametime it is marked read only by writing.TPreadonly name=valueWith no arguments the readonly command lists thenames of all read only variables..TPset [ { -options | +options | -- } ] arg...The set command performs three different functions..spWith no arguments, it lists the values of all shellvariables..spIf options are given, it sets the specified optionflags, or clears them as described in the sectioncalled ``Argument List Processing''..spThe third use of the set command is to set the valuesof the shell's positional parameters to the specifiedargs. To change the positional parameters withoutchanging any options, use ``--'' as the first argument to set. If no args are present, the set commandwill clear all the positional parameters (equivalentto executing ``shift $#''..TPsetvar variable valueAssigns value to variable. (In general it is betterto write variable=value rather than using setvar.Setvar is intended to be used in functions thatassign values to variables whose names are passed asparameters.).TPshift [ n ]Shift the positional parameters n times. A shiftsets the value of $1 to the value of $2, the value of$2 to the value of $3, and so on, decreasing thevalue of $# by one. If there are zero positionalparameters, shifting doesn't do anything..TPtrap [ action ] signal...Cause the shell to parse and execute action when anyof the specified signals are received. The signalsare specified by signal number. Action may be nullor omitted; the former causes the specified signal tobe ignored and the latter causes the default actionto be taken. When the shell forks off a subshell, itresets trapped (but not ignored) signals to thedefault action. The trap command has no effect onsignals that were ignored on entry to the shell..TPumask [ mask ]Set the value of umask (see umask(2)) to the specified octal value.If the argument is omitted, theumask value is printed..TPunalias [-a] [name]If ``name'' is specified, the shell removes that alias.If ``-a'' is specified, all aliases are removed..TPunset name...The specified variables and functions are unset andunexported. If a given name corresponds to both avariable and a function, both the variable and thefunction are unset..TPwait [ job ]Wait for the specified job to complete and return theexit status of the last process in the job. If theargument is omitted, wait for all jobs to completeand the return an exit status of zero..LP.sp 2.B Command Line Editing.sp.LPWhen sh is being used interactively from a terminal, the current commandand the command history (see fc in Builtins) can be edited using vi-modecommand-line editing. This mode uses commands, described below, similarto a subset of those described in the vi man page.The command set -o vi enables vi-mode editing and place sh into viinsert mode.With vi-mode enabled, sh can be switched between insert mode and commandmode. The editor is not described in full here, but will be in a laterdocument. It's similar to vi: typing <ESC> will throw you intocommand VI command mode. Hitting <return> while in command modewill pass the line to the shell.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -