Linux命令:read
在shell中,内建(builtin)命令read,格式如下: read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...] 下面解释read命令各选项的含义。 ”-a aname“:把各个单词依次赋值给数组aname中从0开始的连续下标,赋值之前aname被unset,使用了这个选项就会忽略其它的名称name。 help read1 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 read1 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 :,false, 12 and test builtins do not accept options and do not treat -- specially. The exit,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 |