First, the use of Read
Function: Read input of keyboard
Usage:
①, simple shell read;
Note: If you do not add a variable after read, the default assignment is to reply
[[email protected] opt]# Read (no add variable name after read, default assignment to reply) 123456 [email protected] opt]# echo $REPLY 123456
②, read from the script;
[email protected] opt]# lltotal1756-rw-r--r--.1Root root158May + +: thehosts-rwxr-xr-x.1Root root1783106May - -: $putty-0.62. tar.gz-rw-r--r--.1Root root3May + +: thexx-rwxr-xr-x.1Root root -June5 +: thexx.sh[[email protected]alhost opt]# vim zz.sh[[email protected] opt]# cat zz.sh #!/bin/bashecho "qin shu ru ni de ming zi" Read nameecho "Huan Yin ni: $name"[email protected] opt]# chmod+x zz.sh [[email protected] opt]#./zz.sh qin shu ru ni de Ming Zimachinehuan Yin Ni:machine[[email protected] opt]#
You can also get the following wording:
[ email protected] opt]# vim zz.sh [[email protected] opt]# Cat zz.sh #!/bin/"qin shu ru ni De Ming zi" " " name (note the use of read-p, do not wrap the direct keyboard input). c12> "Huan Yin ni: $name"[[email protected] opt]#. /
Second, the use of arrays array
1, the definition of the array; xx= (AA bb cc DD)
2. View an element inside the array; echo ${xx[2]} (Note: The subscript is starting from 0)
3. View all the elements inside the array; echo ${xx[*]} or Echo ${xx[@]} * @
3. Check the volume label of the array (all subscript); echo ${!xx[*]} or Echo ${!xx[@]} !
4. View the number of elements inside the array; echo ${#xx [*]} or echo ${#xx [@]} #
Forexample:
//definition of an array[Email protected] opt]# mm=(AA bb cc dd) (no commas and semicolons between elements) //view an element in an array[Email protected] opt]# echo ${xx[0]}aa[[email protected] opt]# echo ${xx[3]}dd[[email protected] opt]# echo ${xx[4]} (array subscript is starting from 0) [email protected] opt]#//View all the elements inside the array (*/# all can) [Email protected] opt]# echo ${xx[*]}AA bb cc dd[[email protected] opt]# echo ${XX[@]}AA bb cc dd[[email protected] opt]#//View all subscripts of an array (! ) [Email protected]host opt]# Echo ${!xx[*]}0 1 2 3[email protected] opt]# echo ${!xx[@]}0 1 2 3[email protected] opt]#//view the number of elements inside the array (#) [Email protected] opt]# echo ${#xx [*]}4[ [email protected] opt]# echo ${#xx [@]}4[email protected] opt]#
Shell programming two--read, array,