Linux命令:read

在shell中,内建(builtin)命令read,格式如下:

read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
1
read命令用于从标准输入或选项”-u“指定的文件描述符中读取一行文本,把第一个单词赋值给第一个名称name,第二个单词赋值给第二个名称name,以此类推,剩余的单词连同分隔符一起赋值给最后一个名称name,如果输入的名称name个数比读取的单词个数多,多出来的赋值为空,如果没有指定任何名称name,则把结果赋值给系统变量REPLY。

下面解释read命令各选项的含义。

”-a aname“:把各个单词依次赋值给数组aname中从0开始的连续下标,赋值之前aname被unset,使用了这个选项就会忽略其它的名称name。
”-d delim“:用分隔符delim的第一个字符来结束输入行,而不是换行符。
”-e“:如果标准输入来自shell终端,使用”readline“来读取输入行。
”-i text“:如果使用”readline“来读取输入行,文本text在编辑前被放到编辑缓冲中。
”-n nchars“:最多读取nchars个字符。
”-N nchars“:读取nchars个字符,转义字符不进行转义。
”-p prompt“:如果在shell终端读取输入,首先打印提示prompt,提示不换行。
”-r“:反斜线这个转义字符不作特殊处理,当作普通字符。
”-s“:安静模式,输入来自shell终端时,不进行回显echo。
”-t timeout“:如果在超时时间timeout指定的秒数内还没有读入完整的一行,则读取超时并返回false。timeout可以是个带有小数的十进制数。这个选项只有在read命令从终端、管道、或者其它特殊文件读取输入时才有效,从普通文件读取输入时没有作用。如果timeout为0,则当指定的文件描述符可用时返回true,不可用时返回fasle。如果超时,返回状态大于128。
“-u fd”:从文件描述符fd中读取输入。

help read

 1 read: read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
 2     Read a line from the standard input and split it into fields.
 3     
 4     Reads a single line from the standard input, or from file descriptor FD
 5     if the -u option is supplied.  The line is split into fields as with word
 6     splitting, and the first word is assigned to the first NAME, the second
 7     word to the second NAME, and so on, with any leftover words assigned to
 8     the last NAME.  Only the characters found in $IFS are recognized as word
 9     delimiters.
10     
11     If no NAMEs are supplied, the line read is stored in the REPLY variable.
12     
13     Options:
14       -a array    assign the words read to sequential indices of the array
15             variable ARRAY, starting at zero
16       -d delim    continue until the first character of DELIM is read, rather
17             than newline
18       -e        use Readline to obtain the line in an interactive shell
19       -i text    Use TEXT as the initial text for Readline
20       -n nchars    return after reading NCHARS characters rather than waiting
21             for a newline, but honor a delimiter if fewer than NCHARS
22             characters are read before the delimiter
23       -N nchars    return only after reading exactly NCHARS characters, unless
24             EOF is encountered or read times out, ignoring any delimiter
25       -p prompt    output the string PROMPT without a trailing newline before
26             attempting to read
27       -r        do not allow backslashes to escape any characters
28       -s        do not echo input coming from a terminal
29       -t timeout    time out and return failure if a complete line of input is
30             not read withint TIMEOUT seconds.  The value of the TMOUT
31             variable is the default timeout.  TIMEOUT may be a
32             fractional number.  If TIMEOUT is 0, read returns success only
33             if input is available on the specified file descriptor.  The
34             exit status is greater than 128 if the timeout is exceeded
35       -u fd        read from file descriptor FD instead of the standard input
36     
37     Exit Status:
38     The return code is zero, unless end-of-file is encountered, read times out,
39     or an invalid file descriptor is supplied as the argument to -u.
40 readarray: readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
41     Read lines from a file into an array variable.
42     
43     A synonym for `mapfile'.
44 readonly: readonly [-aAf] [name[=value] ...] or readonly -p
45     Mark shell variables as unchangeable.
46     
47     Mark each NAME as read-only; the values of these NAMEs may not be
48     changed by subsequent assignment.  If VALUE is supplied, assign VALUE
49     before marking as read-only.
50     
51     Options:
52       -a    refer to indexed array variables
53       -A    refer to associative array variables
54       -f    refer to shell functions
55       -p    display a list of all readonly variables and functions
56     
57     An argument of `--' disables further option processing.
58     
59     Exit Status:
60     Returns success unless an invalid option is given or NAME is invalid.

man read

  1 BASH_BUILTINS(1)                                                               General Commands Manual                                                               BASH_BUILTINS(1)
  2 
  3 
  4 
  5 NAME
  6        bash,  :,  .,  [,  alias,  bg, bind, break, builtin, caller, cd, command, compgen, complete, compopt, continue, declare, dirs, disown, echo, enable, eval, exec, exit, export,
  7        false, fc, fg, getopts, hash, help, history, jobs, kill, let, local, logout, mapfile, popd, printf, pushd, pwd, read, readonly, return, set, shift,  shopt,  source,  suspend,
  8        test, times, trap, true, type, typeset, ulimit, umask, unalias, unset, wait - bash built-in commands, see bash(1)
  9 
 10 BASH BUILTIN COMMANDS
 11        Unless  otherwise noted, each builtin command documented in this section as accepting options preceded by - accepts -- to signify the end of the options.  The :, true, false,
 12        and test builtins do not accept options and do not treat -- specially.  The exit, logout, break, continue, let, and shift builtins accept and process arguments beginning with
 13        -  without  requiring --.  Other builtins that accept arguments but are not specified as accepting options interpret arguments beginning with - as invalid options and require
 14        -- to prevent this interpretation.
 15        : [arguments]
 16               No effect; the command does nothing beyond expanding arguments and performing any specified redirections.  A zero exit code is returned.
 17 
 18         .  filename [arguments]
 19        source filename [arguments]
 20               Read and execute commands from filename in the current shell environment and return the exit status of the last command executed from filename.  If filename  does  not
 21               contain  a  slash,  file  names in PATH are used to find the directory containing filename.  The file searched for in PATH need not be executable.  When bash is not in
 22               posix mode, the current directory is searched if no file is found in PATH.  If the sourcepath option to the shopt builtin command  is  turned  off,  the  PATH  is  not
 23               searched.   If  any  arguments  are supplied, they become the positional parameters when filename is executed.  Otherwise the positional parameters are unchanged.  The
 24               return status is the status of the last command exited within the script (0 if no commands are executed), and false if filename is not found or cannot be read.
 25 
 26        alias [-p] [name[=value] ...]
 27               Alias with no arguments or with the -p option prints the list of aliases in the form alias name=value on standard output.  When arguments are  supplied,  an  alias  is
 28               defined for each name whose value is given.  A trailing space in  value causes the next word to be checked for alias substitution when the alias is expanded.  For each
 29               name in the argument list for which no value is supplied, the name and value of the alias is printed.  Alias returns true unless a name is given for which no alias has
 30               been defined.
 31 
 32        bg [jobspec ...]
 33               Resume  each  suspended job jobspec in the background, as if it had been started with &.  If jobspec is not present, the shell's notion of the current job is used.  bg
 34               jobspec returns 0 unless run when job control is disabled or, when run with job control enabled, any specified jobspec was not found or was started  without  job  con‐
 35               trol.
 36 
 37        bind [-m keymap] [-lpsvPSV]
 38        bind [-m keymap] [-q function] [-u function] [-r keyseq]
 39        bind [-m keymap] -f filename
 40        bind [-m keymap] -x keyseq:shell-command
 41        bind [-m keymap] keyseq:function-name
 42        bind readline-command
 43               Display  current  readline  key  and function bindings, bind a key sequence to a readline function or macro, or set a readline variable.  Each non-option argument is a
 44               command as it would appear in .inputrc, but each binding or command must be passed as a separate argument; e.g., '"C-xC-r":  re-read-init-file'.   Options,  if  sup‐
 45               plied, have the following meanings:
 46               -m keymap
 47                      Use  keymap  as  the  keymap to be affected by the subsequent bindings.  Acceptable keymap names are emacs, emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move,
 48                      vi-command, and vi-insert.  vi is equivalent to vi-command; emacs is equivalent to emacs-standard.
 49               -l     List the names of all readline functions.
 50               -p     Display readline function names and bindings in such a way that they can be re-read.
 51               -P     List current readline function names and bindings.
 52               -s     Display readline key sequences bound to macros and the strings they output in such a way that they can be re-read.
 53               -S     Display readline key sequences bound to macros and the strings they output.
 54               -v     Display readline variable names and values in such a way that they can be re-read.
 55               -V     List current readline variable names and values.
 56               -f filename
 57                      Read key bindings from filename.
 58               -q function
 59                      Query about which keys invoke the named function.
 60               -u function
 61                      Unbind all keys bound to the named function.
 62               -r keyseq
 63                      Remove any current binding for keyseq.
 64               -x keyseq:shell-command
 65                      Cause shell-command to be executed whenever keyseq is entered.  When shell-command is executed, the shell sets the READLINE_LINE variable to the contents of the
 66                      readline line buffer and the READLINE_POINT variable to the current location of the insertion point.  If the executed command changes the value of READLINE_LINE
 67                      or READLINE_POINT, those new values will be reflected in the editing state.
 68 
 69               The return value is 0 unless an unrecognized option is given or an error occurred.
 70 
 71        break [n]
 72               Exit from within a for, while, until, or select loop.  If n is specified, break n levels.  n must be ≥ 1.  If n is greater than the  number  of  enclosing  loops,  all
 73               enclosing loops are exited.  The return value is non-zero when n is ≤ 0; Otherwise, break returns 0 value.
 74 
 75        builtin shell-builtin [arguments]
 76               Execute  the  specified  shell  builtin,  passing  it arguments, and return its exit status.  This is useful when defining a function whose name is the same as a shell
 77               builtin, retaining the functionality of the builtin within the function.  The cd builtin is commonly redefined this way.  The return status is false  if  shell-builtin
 78               is not a shell builtin command.
 79 
 80        caller [expr]
 81               Returns the context of any active subroutine call (a shell function or a script executed with the . or source builtins).  Without expr, caller displays the line number
 82               and source filename of the current subroutine call.  If a non-negative integer is supplied as expr, caller displays the line number, subroutine name, and  source  file
 83               corresponding  to  that  position  in the current execution call stack.  This extra information may be used, for example, to print a stack trace.  The current frame is
 84               frame 0.  The return value is 0 unless the shell is not executing a subroutine call or expr does not correspond to a valid position in the call stack.
 85 
 86        cd [-L|[-P [-e]]] [dir]
 87               Change the current directory to dir.  The variable HOME is the default dir.  The variable CDPATH defines the search path for the directory containing dir.  Alternative
 88               directory names in CDPATH are separated by a colon (:).  A null directory name in CDPATH is the same as the current directory, i.e., ``.''.  If dir begins with a slash
 89               (/), then CDPATH is not used. The -P option says to use the physical directory structure instead of following symbolic links (see also the -P option to the set builtin
 90               command);  the  -L  option forces symbolic links to be followed.  If the -e option is supplied with -P, and the current working directory cannot be successfully deter‐
 91               mined after a successful directory change, cd will return an unsuccessful status.  An argument of - is equivalent to $OLDPWD.   If  a  non-empty  directory  name  from
 92               CDPATH  is  used,  or if - is the first argument, and the directory change is successful, the absolute pathname of the new working directory is written to the standard
 93               output.  The return value is true if the directory was successfully changed; false otherwise.
 94 
 95        command [-pVv] command [arg ...]
 96               Run command with args suppressing the normal shell function lookup. Only builtin commands or commands found in the PATH are executed.  If the -p option is  given,  the
 97               search  for command is performed using a default value for PATH that is guaranteed to find all of the standard utilities.  If either the -V or -v option is supplied, a
 98               description of command is printed.  The -v option causes a single word indicating the command or file name used to invoke command to be displayed; the -V  option  pro‐
 99               duces  a  more verbose description.  If the -V or -v option is supplied, the exit status is 0 if command was found, and 1 if not.  If neither option is supplied and an
100               error occurred or command cannot be found, the exit status is 127.  Otherwise, the exit status of the command builtin is the exit status of command.
101 
102        compgen [option] [word]
103               Generate possible completion matches for word according to the options, which may be any option accepted by the complete builtin with the exception of -p and  -r,  and
104               write the matches to the standard output.  When using the -F or -C options, the various shell variables set by the programmable completion facilities, while available,
105               will not have useful values.
106 
107               The matches will be generated in the same way as if the programmable completion code had generated them directly from a completion specification with the  same  flags.
108               If word is specified, only those completions matching word will be displayed.
109 
110               The return value is true unless an invalid option is supplied, or no matches were generated.
111 
112        complete [-abcdefgjksuv] [-o comp-option] [-DE] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command]
113               [-X filterpat] [-P prefix] [-S suffix] name [name ...]
114        complete -pr [-DE] [name ...]
115               Specify how arguments to each name should be completed.  If the -p option is supplied, or if no options are supplied, existing completion specifications are printed in
116               a way that allows them to be reused as input.  The -r option removes a completion specification for each name, or, if no names are supplied, all completion  specifica‐
117               tions.   The  -D option indicates that the remaining options and actions should apply to the ``default'' command completion; that is, completion attempted on a command
118               for which no completion has previously been defined.  The -E option indicates that the remaining options and actions should apply to ``empty'' command completion; that
119               is, completion attempted on a blank line.
120 
121               The process of applying these completion specifications when word completion is attempted is described above under Programmable Completion.
122 
123               Other  options,  if specified, have the following meanings.  The arguments to the -G, -W, and -X options (and, if necessary, the -P and -S options) should be quoted to
124               protect them from expansion before the complete builtin is invoked.
125               -o comp-option
126                       The comp-option controls several aspects of the compspec's behavior beyond the simple generation of completions.  comp-option may be one of:
127                       bashdefault
128                               Perform the rest of the default bash completions if the compspec generates no matches.
129                       default Use readline's default filename completion if the compspec generates no matches.
130                       dirnames
131                               Perform directory name completion if the compspec generates no matches.
132                       filenames
133                               Tell readline that the compspec generates filenames, so it can perform any filename-specific processing (like adding a slash to directory names,  quot‐
134                               ing special characters, or suppressing trailing spaces).  Intended to be used with shell functions.
135                       nospace Tell readline not to append a space (the default) to words completed at the end of the line.
136                       plusdirs
137                               After  any  matches defined by the compspec are generated, directory name completion is attempted and any matches are added to the results of the other
138                               actions.
139               -A action
140                       The action may be one of the following to generate a list of possible completions:
141                       alias   Alias names.  May also be specified as -a.
142                       arrayvar
143                               Array variable names.
144                       binding Readline key binding names.
145                       builtin Names of shell builtin commands.  May also be specified as -b.
146                       command Command names.  May also be specified as -c.
147                       directory
148                               Directory names.  May also be specified as -d.
149                       disabled
150                               Names of disabled shell builtins.
151                       enabled Names of enabled shell builtins.
152                       export  Names of exported shell variables.  May also be specified as -e.
153                       file    File names.  May also be specified as -f.
154                       function
155                               Names of shell functions.
156                       group   Group names.  May also be specified as -g.
157                       helptopic
158                               Help topics as accepted by the help builtin.
159                       hostname
160                               Hostnames, as taken from the file specified by the HOSTFILE shell variable.
161                       job     Job names, if job control is active.  May also be specified as -j.
162                       keyword Shell reserved words.  May also be specified as -k.
163                       running Names of running jobs, if job control is active.
164                       service Service names.  May also be specified as -s.
165                       setopt  Valid arguments for the -o option to the set builtin.
166                       shopt   Shell option names as accepted by the shopt builtin.
167                       signal  Signal names.
168                       stopped Names of stopped jobs, if job control is active.
169                       user    User names.  May also be specified as -u.
170                       variable
171                               Names of all shell variables.  May also be specified as -v.
172               -C command
173                       command is executed in a subshell environment, and its output is used as the possible completions.
174               -F function
175                       The shell function function is executed in the current shell environment.  When it finishes, the possible completions are retrieved from the value of the  COM‐
176                       PREPLY array variable.
177               -G globpat
178                       The pathname expansion pattern globpat is expanded to generate the possible completions.
179               -P prefix
180                       prefix is added at the beginning of each possible completion after all other options have been applied.
181               -S suffix
182                       suffix is appended to each possible completion after all other options have been applied.
183               -W wordlist
184                       The  wordlist  is  split using the characters in the IFS special variable as delimiters, and each resultant word is expanded.  The possible completions are the
185                       members of the resultant list which match the word being completed.
186               -X filterpat
187                       filterpat is a pattern as used for pathname expansion.  It is applied to the list of possible completions generated by the preceding options and arguments, and
188                       each completion matching filterpat is removed from the list.  A leading ! in filterpat negates the pattern; in this case, any completion not matching filterpat
189                       is removed.
190 
191               The return value is true unless an invalid option is supplied, an option other than -p or -r is supplied without a name argument, an attempt is made to remove  a  com‐
192               pletion specification for a name for which no specification exists, or an error occurs adding a completion specification.
193 
194        compopt [-o option] [-DE] [+o option] [name]
195               Modify completion options for each name according to the options, or for the currently-executing completion if no names are supplied.  If no options are given, display
196               the completion options for each name or the current completion.  The possible values of option are those valid for the complete builtin described above.  The -D option
197               indicates  that the remaining options should apply to the ``default'' command completion; that is, completion attempted on a command for which no completion has previ‐
198               ously been defined.  The -E option indicates that the remaining options should apply to ``empty'' command completion; that is, completion attempted on a blank line.
199 
200               The return value is true unless an invalid option is supplied, an attempt is made to modify the options for a name for which no completion specification exists, or  an
201               output error occurs.
202 
203        continue [n]
204               Resume  the  next  iteration of the enclosing for, while, until, or select loop.  If n is specified, resume at the nth enclosing loop.  n must be ≥ 1.  If n is greater
205               than the number of enclosing loops, the last enclosing loop (the ``top-level'' loop) is resumed.  When continue is executed inside of loop, the return  value  is  non-
206               zero when n is ≤ 0; Otherwise, continue returns 0 value. When continue is executed outside of loop, the return value is 0.
207 
208        declare [-aAfFgilrtux] [-p] [name[=value] ...]
209        typeset [-aAfFgilrtux] [-p] [name[=value] ...]
210               Declare  variables  and/or  give them attributes.  If no names are given then display the values of variables.  The -p option will display the attributes and values of
211               each name.  When -p is used with name arguments, additional options are ignored.  When -p is supplied without name arguments, it will display the attributes and values
212               of  all  variables having the attributes specified by the additional options.  If no other options are supplied with -p, declare will display the attributes and values
213               of all shell variables.  The -f option will restrict the display to shell functions.  The -F option inhibits the display of function  definitions;  only  the  function
214               name and attributes are printed.  If the extdebug shell option is enabled using shopt, the source file name and line number where the function is defined are displayed
215               as well.  The -F option implies -f.  The -g option forces variables to be created or modified at the global scope, even when declare is executed in a  shell  function.
216               It is ignored in all other cases.  The following options can be used to restrict output to variables with the specified attribute or to give variables attributes:
217               -a     Each name is an indexed array variable (see Arrays above).
218               -A     Each name is an associative array variable (see Arrays above).
219               -f     Use function names only.
220               -i     The variable is treated as an integer; arithmetic evaluation (see ARITHMETIC EVALUATION above) is performed when the variable is assigned a value.
221               -l     When the variable is assigned a value, all upper-case characters are converted to lower-case.  The upper-case attribute is disabled.
222               -r     Make names readonly.  These names cannot then be assigned values by subsequent assignment statements or unset.
223               -t     Give each name the trace attribute.  Traced functions inherit the DEBUG and RETURN traps from the calling shell.  The trace attribute has no special meaning for
224                      variables.
225               -u     When the variable is assigned a value, all lower-case characters are converted to upper-case.  The lower-case attribute is disabled.
226               -x     Mark names for export to subsequent commands via the environment.
227 
228               Using `+' instead of `-' turns off the attribute instead, with the exceptions that +a may not be used to destroy an array variable and +r will not remove the  readonly
229               attribute.   When used in a function, makes each name local, as with the local command, unless the -g option is supplied, If a variable name is followed by =value, the
230               value of the variable is set to value.  The return value is 0 unless an invalid option is encountered, an attempt is made to define a function using ``-f foo=bar'', an
231               attempt  is  made to assign a value to a readonly variable, an attempt is made to assign a value to an array variable without using the compound assignment syntax (see
232               Arrays above), one of the names is not a valid shell variable name, an attempt is made to turn off readonly status for a readonly variable, an attempt is made to  turn
233               off array status for an array variable, or an attempt is made to display a non-existent function with -f.
234 
235        dirs [+n] [-n] [-clpv]
236               Without options, displays the list of currently remembered directories.  The default display is on a single line with directory names separated by spaces.  Directories
237               are added to the list with the pushd command; the popd command removes entries from the list.
238               +n     Displays the nth entry counting from the left of the list shown by dirs when invoked without options, starting with zero.
239               -n     Displays the nth entry counting from the right of the list shown by dirs when invoked without options, starting with zero.
240               -c     Clears the directory stack by deleting all of the entries.
241               -l     Produces a longer listing; the default listing format uses a tilde to denote the home directory.
242               -p     Print the directory stack with one entry per line.
243               -v     Print the directory stack with one entry per line, prefixing each entry with its index in the stack.
244 
245               The return value is 0 unless an invalid option is supplied or n indexes beyond the end of the directory stack.
246 
247        disown [-ar] [-h] [jobspec ...]
248               Without options, each jobspec is removed from the table of active jobs.  If jobspec is not present, and neither -a nor -r is supplied, the shell's notion of  the  cur‐
249               rent  job  is used.  If the -h option is given, each jobspec is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a
250               SIGHUP.  If no jobspec is present, and neither the -a nor the -r option is supplied, the current job is used.  If no jobspec is supplied, the -a option means to remove
251               or mark all jobs; the -r option without a jobspec argument restricts operation to running jobs.  The return value is 0 unless a jobspec does not specify a valid job.
252 
253        echo [-neE] [arg ...]
254               Output the args, separated by spaces, followed by a newline.  The return status is always 0.  If -n is specified, the trailing newline is suppressed.  If the -e option
255               is given, interpretation of the following backslash-escaped characters is enabled.  The -E option disables the interpretation of these escape characters, even on  sys‐
256               tems  where  they  are  interpreted  by default.  The xpg_echo shell option may be used to dynamically determine whether or not echo expands these escape characters by
257               default.  echo does not interpret -- to mean the end of options.  echo interprets the following escape sequences:
258               a     alert (bell)
259                    backspace
260               c     suppress further output
261               e
262               E     an escape character
263               f     form feed
264               
     new line
265               
     carriage return
266               	     horizontal tab
267               v     vertical tab
268               \     backslash
269               nnn  the eight-bit character whose value is the octal value nnn (zero to three octal digits)
270               xHH   the eight-bit character whose value is the hexadecimal value HH (one or two hex digits)
271               uHHHH the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value HHHH (one to four hex digits)
272               UHHHHHHHH
273                      the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value HHHHHHHH (one to eight hex digits)
274 
275        enable [-a] [-dnps] [-f filename] [name ...]
276               Enable and disable builtin shell commands.  Disabling a builtin allows a disk command which has the same name as a shell builtin to be executed  without  specifying  a
277               full  pathname,  even  though  the shell normally searches for builtins before disk commands.  If -n is used, each name is disabled; otherwise, names are enabled.  For
278               example, to use the test binary found via the PATH instead of the shell builtin version, run ``enable -n test''.  The -f option means to load the new  builtin  command
279               name  from  shared  object filename, on systems that support dynamic loading.  The -d option will delete a builtin previously loaded with -f.  If no name arguments are
280               given, or if the -p option is supplied, a list of shell builtins is printed.  With no other option arguments, the list consists of all enabled shell builtins.   If  -n
281               is  supplied, only disabled builtins are printed.  If -a is supplied, the list printed includes all builtins, with an indication of whether or not each is enabled.  If
282               -s is supplied, the output is restricted to the POSIX special builtins.  The return value is 0 unless a name is not a shell builtin or there is an error loading a  new
283               builtin from a shared object.
284 
285        eval [arg ...]
286               The  args  are read and concatenated together into a single command.  This command is then read and executed by the shell, and its exit status is returned as the value
287               of eval.  If there are no args, or only null arguments, eval returns 0.
288 
289        exec [-cl] [-a name] [command [arguments]]
290               If command is specified, it replaces the shell.  No new process is created.  The arguments become the arguments to command.  If the -l option is  supplied,  the  shell
291               places  a dash at the beginning of the zeroth argument passed to command.  This is what login(1) does.  The -c option causes command to be executed with an empty envi‐
292               ronment.  If -a is supplied, the shell passes name as the zeroth argument to the executed command.  If command cannot be executed for some  reason,  a  non-interactive
293               shell  exits,  unless the shell option execfail is enabled, in which case it returns failure.  An interactive shell returns failure if the file cannot be executed.  If
294               command is not specified, any redirections take effect in the current shell, and the return status is 0.  If there is a redirection error, the return status is 1.
295 
296        exit [n]
297               Cause the shell to exit with a status of n.  If n is omitted, the exit status is that of the last command executed.  A trap on EXIT is executed before the shell termi‐
298               nates.
299 
300        export [-fn] [name[=word]] ...
301        export -p
302               The  supplied names are marked for automatic export to the environment of subsequently executed commands.  If the -f option is given, the names refer to functions.  If
303               no names are given, or if the -p option is supplied, a list of all names that are exported in this shell is printed.  The -n option causes the export  property  to  be
304               removed  from  each  name.   If  a  variable name is followed by =word, the value of the variable is set to word.  export returns an exit status of 0 unless an invalid
305               option is encountered, one of the names is not a valid shell variable name, or -f is supplied with a name that is not a function.
306 
307        fc [-e ename] [-lnr] [first] [last]
308        fc -s [pat=rep] [cmd]
309               Fix Command.  In the first form, a range of commands from first to last is selected from the history list.  First and last may be specified as a string (to locate  the
310               last command beginning with that string) or as a number (an index into the history list, where a negative number is used as an offset from the current command number).
311               If last is not specified it is set to the current command for listing (so that ``fc -l -10'' prints the last 10 commands) and to first  otherwise.   If  first  is  not
312               specified it is set to the previous command for editing and -16 for listing.
313 
314               The  -n  option  suppresses the command numbers when listing.  The -r option reverses the order of the commands.  If the -l option is given, the commands are listed on
315               standard output.  Otherwise, the editor given by ename is invoked on a file containing those commands.  If ename is not given, the value  of  the  FCEDIT  variable  is
316               used, and the value of EDITOR if FCEDIT is not set.  If neither variable is set, is used.  When editing is complete, the edited commands are echoed and executed.
317 
318               In  the  second  form, command is re-executed after each instance of pat is replaced by rep.  A useful alias to use with this is ``r="fc -s"'', so that typing ``r cc''
319               runs the last command beginning with ``cc'' and typing ``r'' re-executes the last command.
320 
321               If the first form is used, the return value is 0 unless an invalid option is encountered or first or last specify history lines out of range.  If the -e option is sup‐
322               plied,  the  return value is the value of the last command executed or failure if an error occurs with the temporary file of commands.  If the second form is used, the
323               return status is that of the command re-executed, unless cmd does not specify a valid history line, in which case fc returns failure.
324 
325        fg [jobspec]
326               Resume jobspec in the foreground, and make it the current job.  If jobspec is not present, the shell's notion of the current job is used.  The return value is that  of
327               the  command  placed into the foreground, or failure if run when job control is disabled or, when run with job control enabled, if jobspec does not specify a valid job
328               or jobspec specifies a job that was started without job control.
329 
330        getopts optstring name [args]
331               getopts is used by shell procedures to parse positional parameters.  optstring contains the option characters to be recognized; if a character is followed by a  colon,
332               the option is expected to have an argument, which should be separated from it by white space.  The colon and question mark characters may not be used as option charac‐
333               ters.  Each time it is invoked, getopts places the next option in the shell variable name, initializing name if it does not exist, and the index of the  next  argument
334               to  be  processed into the variable OPTIND.  OPTIND is initialized to 1 each time the shell or a shell script is invoked.  When an option requires an argument, getopts
335               places that argument into the variable OPTARG.  The shell does not reset OPTIND automatically; it must be manually reset between multiple calls to getopts  within  the
336               same shell invocation if a new set of parameters is to be used.
337 
338               When  the end of options is encountered, getopts exits with a return value greater than zero.  OPTIND is set to the index of the first non-option argument, and name is
339               set to ?.
340 
341               getopts normally parses the positional parameters, but if more arguments are given in args, getopts parses those instead.
342 
343               getopts can report errors in two ways.  If the first character of optstring is a colon, silent error reporting is used.  In normal operation  diagnostic  messages  are
344               printed  when  invalid options or missing option arguments are encountered.  If the variable OPTERR is set to 0, no error messages will be displayed, even if the first
345               character of optstring is not a colon.
346 
347               If an invalid option is seen, getopts places ? into name and, if not silent, prints an error message and unsets OPTARG.  If getopts is  silent,  the  option  character
348               found is placed in OPTARG and no diagnostic message is printed.
349 
350               If  a  required  argument  is  not  found,  and getopts is not silent, a question mark (?) is placed in name, OPTARG is unset, and a diagnostic message is printed.  If
351               getopts is silent, then a colon (:) is placed in name and OPTARG is set to the option character found.
352 
353               getopts returns true if an option, specified or unspecified, is found.  It returns false if the end of options is encountered or an error occurs.
354 
355        hash [-lr] [-p filename] [-dt] [name]
356               Each time hash is invoked, the full pathname of the command name is determined by searching the directories in $PATH and remembered.  Any  previously-remembered  path‐
357               name  is  discarded.   If  the -p option is supplied, no path search is performed, and filename is used as the full file name of the command.  The -r option causes the
358               shell to forget all remembered locations.  The -d option causes the shell to forget the remembered location of each name.  If the -t option is supplied, the full path‐
359               name  to  which each name corresponds is printed.  If multiple name arguments are supplied with -t, the name is printed before the hashed full pathname.  The -l option
360               causes output to be displayed in a format that may be reused as input.  If no arguments are given, or if only -l is supplied, information about remembered commands  is
361               printed.  The return status is true unless a name is not found or an invalid option is supplied.
362 
363        help [-dms] [pattern]
364               Display  helpful  information  about  builtin commands.  If pattern is specified, help gives detailed help on all commands matching pattern; otherwise help for all the
365               builtins and shell control structures is printed.
366               -d     Display a short description of each pattern
367               -m     Display the description of each pattern in a manpage-like format
368               -s     Display only a short usage synopsis for each pattern
369 
370               The return status is 0 unless no command matches pattern.
371 
372        history [n]
373        history -c
374        history -d offset
375        history -anrw [filename]
376        history -p arg [arg ...]
377        history -s arg [arg ...]
378               With no options, display the command history list with line numbers.  Lines listed with a * have been modified.  An argument of n lists only the last n lines.  If  the
379               shell  variable  HISTTIMEFORMAT  is  set  and  not null, it is used as a format string for strftime(3) to display the time stamp associated with each displayed history
380               entry.  No intervening blank is printed between the formatted time stamp and the history line.  If filename is supplied, it is used as the name of the history file; if
381               not, the value of HISTFILE is used.  Options, if supplied, have the following meanings:
382               -c     Clear the history list by deleting all the entries.
383               -d offset
384                      Delete the history entry at position offset.
385               -a     Append the ``new'' history lines (history lines entered since the beginning of the current bash session) to the history file.
386               -n     Read  the  history lines not already read from the history file into the current history list.  These are lines appended to the history file since the beginning
387                      of the current bash session.
388               -r     Read the contents of the history file and use them as the current history.
389               -w     Write the current history to the history file, overwriting the history file's contents.
390               -p     Perform history substitution on the following args and display the result on the standard output.  Does not store the results in the  history  list.   Each  arg
391                      must be quoted to disable normal history expansion.
392               -s     Store the args in the history list as a single entry.  The last command in the history list is removed before the args are added.
393 
394               If  the  HISTTIMEFORMAT  variable is set, the time stamp information associated with each history entry is written to the history file, marked with the history comment
395               character.  When the history file is read, lines beginning with the history comment character followed immediately by a digit are interpreted  as  timestamps  for  the
396               previous  history line.  The return value is 0 unless an invalid option is encountered, an error occurs while reading or writing the history file, an invalid offset is
397               supplied as an argument to -d, or the history expansion supplied as an argument to -p fails.
398 
399        jobs [-lnprs] [ jobspec ... ]
400        jobs -x command [ args ... ]
401               The first form lists the active jobs.  The options have the following meanings:
402               -l     List process IDs in addition to the normal information.
403               -n     Display information only about jobs that have changed status since the user was last notified of their status.
404               -p     List only the process ID of the job's process group leader.
405               -r     Restrict output to running jobs.
406               -s     Restrict output to stopped jobs.
407 
408               If jobspec is given, output is restricted to information about that job.  The return status is 0 unless an invalid option is encountered or an invalid jobspec is  sup‐
409               plied.
410 
411               If the -x option is supplied, jobs replaces any jobspec found in command or args with the corresponding process group ID, and executes command passing it args, return‐
412               ing its exit status.
413 
414        kill [-s sigspec | -n signum | -sigspec] [pid | jobspec] ...
415        kill -l [sigspec | exit_status]
416               Send the signal named by sigspec or signum to the processes named by pid or jobspec.  sigspec is either a case-insensitive signal name such as SIGKILL (with or without
417               the  SIG prefix) or a signal number; signum is a signal number.  If sigspec is not present, then SIGTERM is assumed.  An argument of -l lists the signal names.  If any
418               arguments are supplied when -l is given, the names of the signals corresponding to the arguments are listed, and the return status is 0.  The exit_status  argument  to
419               -l  is  a  number  specifying either a signal number or the exit status of a process terminated by a signal.  kill returns true if at least one signal was successfully
420               sent, or false if an error occurs or an invalid option is encountered.
421 
422        let arg [arg ...]
423               Each arg is an arithmetic expression to be evaluated (see ARITHMETIC EVALUATION above).  If the last arg evaluates to 0, let returns 1; 0 is returned otherwise.
424 
425        local [option] [name[=value] ...]
426               For each argument, a local variable named name is created, and assigned value.  The option can be any of the options accepted by declare.  When local is used within  a
427               function,  it  causes the variable name to have a visible scope restricted to that function and its children.  With no operands, local writes a list of local variables
428               to the standard output.  It is an error to use local when not within a function.  The return status is 0 unless local is used outside a function, an  invalid  name  is
429               supplied, or name is a readonly variable.
430 
431        logout Exit a login shell.
432 
433        mapfile [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
434        readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
435               Read lines from the standard input into the indexed array variable array, or from file descriptor fd if the -u option is supplied.  The variable MAPFILE is the default
436               array.  Options, if supplied, have the following meanings:
437               -n     Copy at most count lines.  If count is 0, all lines are copied.
438               -O     Begin assigning to array at index origin.  The default index is 0.
439               -s     Discard the first count lines read.
440               -t     Remove a trailing newline from each line read.
441               -u     Read lines from file descriptor fd instead of the standard input.
442               -C     Evaluate callback each time quantum lines are read.  The -c option specifies quantum.
443               -c     Specify the number of lines read between each call to callback.
444 
445               If -C is specified without -c, the default quantum is 5000.  When callback is evaluated, it is supplied the index of the next array element to be assigned and the line
446               to be assigned to that element as additional arguments.  callback is evaluated after the line is read but before the array element is assigned.
447 
448               If not supplied with an explicit origin, mapfile will clear array before assigning to it.
449 
450               mapfile returns successfully unless an invalid option or option argument is supplied, array is invalid or unassignable, or if array is not an indexed array.
451 
452        popd [-n] [+n] [-n]
453               Removes entries from the directory stack.  With no arguments, removes the top directory from the stack, and performs a cd to the new top directory.  Arguments, if sup‐
454               plied, have the following meanings:
455               -n     Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated.
456               +n     Removes the nth entry counting from the left of the list shown by dirs, starting with zero.  For example: ``popd +0'' removes the first directory,  ``popd  +1''
457                      the second.
458               -n     Removes  the  nth entry counting from the right of the list shown by dirs, starting with zero.  For example: ``popd -0'' removes the last directory, ``popd -1''
459                      the next to last.
460 
461               If the popd command is successful, a dirs is performed as well, and the return status is 0.  popd returns false if an invalid  option  is  encountered,  the  directory
462               stack is empty, a non-existent directory stack entry is specified, or the directory change fails.
463 
464        printf [-v var] format [arguments]
465               Write  the  formatted arguments to the standard output under the control of the format.  The -v option causes the output to be assigned to the variable var rather than
466               being printed to the standard output.
467 
468               The format is a character string which contains three types of objects: plain characters, which are simply copied to standard output, character escape sequences, which
469               are converted and copied to the standard output, and format specifications, each of which causes printing of the next successive argument.  In addition to the standard
470               printf(1) format specifications, printf interprets the following extensions:
471               %b     causes printf to expand backslash escape sequences in the corresponding argument (except that c terminates output, backslashes  in  ',  ",  and  ?  are  not
472                      removed, and octal escapes beginning with 0 may contain up to four digits).
473               %q     causes printf to output the corresponding argument in a format that can be reused as shell input.
474               %(datefmt)T
475                      causes  printf  to output the date-time string resulting from using datefmt as a format string for strftime(3).  The corresponding argument is an integer repre‐
476                      senting the number of seconds since the epoch.  Two special argument values may be used: -1 represents the current time, and -2 represents the  time  the  shell
477                      was invoked.
478 
479               Arguments  to non-string format specifiers are treated as C constants, except that a leading plus or minus sign is allowed, and if the leading character is a single or
480               double quote, the value is the ASCII value of the following character.
481 
482               The format is reused as necessary to consume all of the arguments.  If the format requires more arguments than are supplied, the extra format specifications behave  as
483               if a zero value or null string, as appropriate, had been supplied.  The return value is zero on success, non-zero on failure.
484 
485        pushd [-n] [+n] [-n]
486        pushd [-n] [dir]
487               Adds  a directory to the top of the directory stack, or rotates the stack, making the new top of the stack the current working directory.  With no arguments, exchanges
488               the top two directories and returns 0, unless the directory stack is empty.  Arguments, if supplied, have the following meanings:
489               -n     Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated.
490               +n     Rotates the stack so that the nth directory (counting from the left of the list shown by dirs, starting with zero) is at the top.
491               -n     Rotates the stack so that the nth directory (counting from the right of the list shown by dirs, starting with zero) is at the top.
492               dir    Adds dir to the directory stack at the top, making it the new current working directory.
493 
494               If the pushd command is successful, a dirs is performed as well.  If the first form is used, pushd returns 0 unless the cd to dir fails.  With the second  form,  pushd
495               returns  0  unless  the  directory  stack is empty, a non-existent directory stack element is specified, or the directory change to the specified new current directory
496               fails.
497 
498        pwd [-LP]
499               Print the absolute pathname of the current working directory.  The pathname printed contains no symbolic links if the -P option is supplied or the -o  physical  option
500               to the set builtin command is enabled.  If the -L option is used, the pathname printed may contain symbolic links.  The return status is 0 unless an error occurs while
501               reading the name of the current directory or an invalid option is supplied.
502 
503        read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
504               One line is read from the standard input, or from the file descriptor fd supplied as an argument to the -u option, and the first word is assigned to  the  first  name,
505               the  second word to the second name, and so on, with leftover words and their intervening separators assigned to the last name.  If there are fewer words read from the
506               input stream than names, the remaining names are assigned empty values.  The characters in IFS are used to split the line into words.  The backslash character ()  may
507               be used to remove any special meaning for the next character read and for line continuation.  Options, if supplied, have the following meanings:
508               -a aname
509                      The  words  are assigned to sequential indices of the array variable aname, starting at 0.  aname is unset before any new values are assigned.  Other name argu‐
510                      ments are ignored.
511               -d delim
512                      The first character of delim is used to terminate the input line, rather than newline.
513               -e     If the standard input is coming from a terminal, readline (see READLINE above) is used to obtain the line.  Readline uses the current (or default, if line edit‐
514                      ing was not previously active) editing settings.
515               -i text
516                      If readline is being used to read the line, text is placed into the editing buffer before editing begins.
517               -n nchars
518                      read  returns  after  reading nchars characters rather than waiting for a complete line of input, but honor a delimiter if fewer than nchars characters are read
519                      before the delimiter.
520               -N nchars
521                      read returns after reading exactly nchars characters rather than waiting for a complete line of input, unless EOF is encountered or read times  out.   Delimiter
522                      characters encountered in the input are not treated specially and do not cause read to return until nchars characters are read.
523               -p prompt
524                      Display  prompt on standard error, without a trailing newline, before attempting to read any input.  The prompt is displayed only if input is coming from a ter‐
525                      minal.
526               -r     Backslash does not act as an escape character.  The backslash is considered to be part of the line.  In particular, a backslash-newline pair may not be used  as
527                      a line continuation.
528               -s     Silent mode.  If input is coming from a terminal, characters are not echoed.
529               -t timeout
530                      Cause  read  to  time  out and return failure if a complete line of input is not read within timeout seconds.  timeout may be a decimal number with a fractional
531                      portion following the decimal point.  This option is only effective if read is reading input from a terminal, pipe, or other special file; it has no effect when
532                      reading  from  regular files.  If timeout is 0, read returns success if input is available on the specified file descriptor, failure otherwise.  The exit status
533                      is greater than 128 if the timeout is exceeded.
534               -u fd  Read input from file descriptor fd.
535 
536               If no names are supplied, the line read is assigned to the variable REPLY.  The return code is zero, unless end-of-file is encountered, read times out (in  which  case
537               the return code is greater than 128), or an invalid file descriptor is supplied as the argument to -u.
538 
539        readonly [-aAf] [-p] [name[=word] ...]
540               The  given names are marked readonly; the values of these names may not be changed by subsequent assignment.  If the -f option is supplied, the functions corresponding
541               to the names are so marked.  The -a option restricts the variables to indexed arrays; the -A option restricts the variables to associative arrays.  If both options are
542               supplied,  -A  takes  precedence.   If no name arguments are given, or if the -p option is supplied, a list of all readonly names is printed.  The other options may be
543               used to restrict the output to a subset of the set of readonly names.  The -p option causes output to be displayed in a format that may be reused as input.  If a vari‐
544               able  name  is  followed by =word, the value of the variable is set to word.  The return status is 0 unless an invalid option is encountered, one of the names is not a
545               valid shell variable name, or -f is supplied with a name that is not a function.
546 
547        return [n]
548               Causes a function to exit with the return value specified by n.  If n is omitted, the return status is that of the last command executed in the function body.  If used
549               outside a function, but during execution of a script by the .  (source) command, it causes the shell to stop executing that script and return either n or the exit sta‐
550               tus of the last command executed within the script as the exit status of the script.  If used outside a function and not during execution of a script by ., the  return
551               status is false.  Any command associated with the RETURN trap is executed before execution resumes after the function or script.
552 
553        set [--abefhkmnptuvxBCEHPT] [-o option-name] [arg ...]
554        set [+abefhkmnptuvxBCEHPT] [+o option-name] [arg ...]
555               Without  options, the name and value of each shell variable are displayed in a format that can be reused as input for setting or resetting the currently-set variables.
556               Read-only variables cannot be reset.  In posix mode, only shell variables are listed.  The output is sorted according to the current locale.  When options  are  speci‐
557               fied,  they  set  or  unset shell attributes.  Any arguments remaining after option processing are treated as values for the positional parameters and are assigned, in
558               order, to $1, $2, ...  $n.  Options, if specified, have the following meanings:
559               -a      Automatically mark variables and functions which are modified or created for export to the environment of subsequent commands.
560               -b      Report the status of terminated background jobs immediately, rather than before the next primary prompt.  This is effective only when job control is enabled.
561               -e      Exit immediately if a pipeline (which may consist of a single simple command),  a subshell command enclosed in parentheses, or one of the commands executed  as
562                       part of a command list enclosed by braces (see SHELL GRAMMAR above) exits with a non-zero status.  The shell does not exit if the command that fails is part of
563                       the command list immediately following a while or until keyword, part of the test following the if or elif reserved words, part of any command executed in a &&
564                       or  || list except the command following the final && or ||, any command in a pipeline but the last, or if the command's return value is being inverted with !.
565                       A trap on ERR, if set, is executed before the shell exits.  This option applies to the shell environment and each subshell environment separately (see  COMMAND
566                       EXECUTION ENVIRONMENT above), and may cause subshells to exit before executing all the commands in the subshell.
567               -f      Disable pathname expansion.
568               -h      Remember the location of commands as they are looked up for execution.  This is enabled by default.
569               -k      All arguments in the form of assignment statements are placed in the environment for a command, not just those that precede the command name.
570               -m      Monitor  mode.   Job  control  is enabled.  This option is on by default for interactive shells on systems that support it (see JOB CONTROL above).  Background
571                       processes run in a separate process group and a line containing their exit status is printed upon their completion.
572               -n      Read commands but do not execute them.  This may be used to check a shell script for syntax errors.  This is ignored by interactive shells.
573               -o option-name
574                       The option-name can be one of the following:
575                       allexport
576                               Same as -a.
577                       braceexpand
578                               Same as -B.
579                       emacs   Use an emacs-style command line editing interface.  This is enabled by default when the shell is interactive, unless the  shell  is  started  with  the
580                               --noediting option.  This also affects the editing interface used for read -e.
581                       errexit Same as -e.
582                       errtrace
583                               Same as -E.
584                       functrace
585                               Same as -T.
586                       hashall Same as -h.
587                       histexpand
588                               Same as -H.
589                       history Enable command history, as described above under HISTORY.  This option is on by default in interactive shells.
590                       ignoreeof
591                               The effect is as if the shell command ``IGNOREEOF=10'' had been executed (see Shell Variables above).
592                       keyword Same as -k.
593                       monitor Same as -m.
594                       noclobber
595                               Same as -C.
596                       noexec  Same as -n.
597                       noglob  Same as -f.
598                       nolog   Currently ignored.
599                       notify  Same as -b.
600                       nounset Same as -u.
601                       onecmd  Same as -t.
602                       physical
603                               Same as -P.
604                       pipefail
605                               If  set,  the  return  value  of a pipeline is the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands in the
606                               pipeline exit successfully.  This option is disabled by default.
607                       posix   Change the behavior of bash where the default operation differs from the POSIX standard to match the standard (posix mode).
608                       privileged
609                               Same as -p.
610                       verbose Same as -v.
611                       vi      Use a vi-style command line editing interface.  This also affects the editing interface used for read -e.
612                       xtrace  Same as -x.
613                       If -o is supplied with no option-name, the values of the current options are printed.  If +o is supplied with no option-name,  a  series  of  set  commands  to
614                       recreate the current option settings is displayed on the standard output.
615               -p      Turn  on  privileged mode.  In this mode, the $ENV and $BASH_ENV files are not processed, shell functions are not inherited from the environment, and the SHEL‐
616                       LOPTS, BASHOPTS, CDPATH, and GLOBIGNORE variables, if they appear in the environment, are ignored.  If the shell is started with the effective user (group)  id
617                       not equal to the real user (group) id, and the -p option is not supplied, these actions are taken and the effective user id is set to the real user id.  If the
618                       -p option is supplied at startup, the effective user id is not reset.  Turning this option off causes the effective user and group ids to be set  to  the  real
619                       user and group ids.
620               -t      Exit after reading and executing one command.
621               -u      Treat  unset variables and parameters other than the special parameters "@" and "*" as an error when performing parameter expansion.  If expansion is attempted
622                       on an unset variable or parameter, the shell prints an error message, and, if not interactive, exits with a non-zero status.
623               -v      Print shell input lines as they are read.
624               -x      After expanding each simple command, for command, case command, select command, or arithmetic for command, display the expanded value of PS4, followed  by  the
625                       command and its expanded arguments or associated word list.
626               -B      The shell performs brace expansion (see Brace Expansion above).  This is on by default.
627               -C      If  set, bash does not overwrite an existing file with the >, >&, and <> redirection operators.  This may be overridden when creating output files by using the
628                       redirection operator >| instead of >.
629               -E      If set, any trap on ERR is inherited by shell functions, command substitutions, and commands executed in a subshell environment.  The ERR trap is normally  not
630                       inherited in such cases.
631               -H      Enable !  style history substitution.  This option is on by default when the shell is interactive.
632               -P      If  set, the shell does not follow symbolic links when executing commands such as cd that change the current working directory.  It uses the physical directory
633                       structure instead.  By default, bash follows the logical chain of directories when performing commands which change the current directory.
634               -T      If set, any traps on DEBUG and RETURN are inherited by shell functions, command substitutions, and commands executed in a subshell environment.  The DEBUG  and
635                       RETURN traps are normally not inherited in such cases.
636               --      If  no  arguments follow this option, then the positional parameters are unset.  Otherwise, the positional parameters are set to the args, even if some of them
637                       begin with a -.
638               -       Signal the end of options, cause all remaining args to be assigned to the positional parameters.  The -x and -v options are turned off.  If there are no  args,
639                       the positional parameters remain unchanged.
640 
641               The options are off by default unless otherwise noted.  Using + rather than - causes these options to be turned off.  The options can also be specified as arguments to
642               an invocation of the shell.  The current set of options may be found in $-.  The return status is always true unless an invalid option is encountered.
643 
644        shift [n]
645               The positional parameters from n+1 ... are renamed to $1 ....  Parameters represented by the numbers $# down to $#-n+1 are unset.  n must be a non-negative number less
646               than  or  equal  to  $#.   If n is 0, no parameters are changed.  If n is not given, it is assumed to be 1.  If n is greater than $#, the positional parameters are not
647               changed.  The return status is greater than zero if n is greater than $# or less than zero; otherwise 0.
648 
649        shopt [-pqsu] [-o] [optname ...]
650               Toggle the values of variables controlling optional shell behavior.  With no options, or with the -p option, a list of all settable options is displayed, with an indi‐
651               cation of whether or not each is set.  The -p option causes output to be displayed in a form that may be reused as input.  Other options have the following meanings:
652               -s     Enable (set) each optname.
653               -u     Disable (unset) each optname.
654               -q     Suppresses  normal  output  (quiet mode); the return status indicates whether the optname is set or unset.  If multiple optname arguments are given with -q, the
655                      return status is zero if all optnames are enabled; non-zero otherwise.
656               -o     Restricts the values of optname to be those defined for the -o option to the set builtin.
657 
658               If either -s or -u is used with no optname arguments, the display is limited to those options which are set or unset, respectively.  Unless otherwise noted, the  shopt
659               options are disabled (unset) by default.
660 
661               The return status when listing options is zero if all optnames are enabled, non-zero otherwise.  When setting or unsetting options, the return status is zero unless an
662               optname is not a valid shell option.
663 
664               The list of shopt options is:
665 
666               autocd  If set, a command name that is the name of a directory is executed as if it were the argument to the cd command.  This  option  is  only  used  by  interactive
667                       shells.
668               cdable_vars
669                       If set, an argument to the cd builtin command that is not a directory is assumed to be the name of a variable whose value is the directory to change to.
670               cdspell If  set,  minor errors in the spelling of a directory component in a cd command will be corrected.  The errors checked for are transposed characters, a missing
671                      
 1 $ read foo
 2 hello world
 3 $ echo $foo
 4 hello world
 5 $ read foo bar
 6 hello world
 7 $ echo $foo
 8 hello
 9 $ echo $bar
10 world
11 $ read
12 hello world
13 $ echo $REPLY
14 hello world
15 $ read -a foo
16 hello a b c
17 $ echo ${foo[@]}
18 hello a b c
19 $ echo ${#foo[@]}
20 4
21 $ echo ${foo[0]}
22 hello
23 $ echo ${foo[3]}
24 c
25 $ read -p "Please input a string:" foo
26 Please input a string:hello
27 $ echo $foo
28 hello
本篇文章出自“国民时代”,转载请注明转载出处。
原文地址:https://www.cnblogs.com/ChinaGo/p/10626814.html