#!/bin/bashwhile ifs=: Read name1 name2 name3 name4#ifs is the split symbol specified when reading from a file, assigning the contents of a to the corresponding variable in separate sections. Do echo $name 1 ' | ' $name 2 ' | ' $name 3 ' | ' $name 4 done <a# anti-quote and $ () function is command substitution, which will be executed as a command in the inverse quotation mark or the string in $ (), but the back quotation mark cannot continue to have the anti-quote, while $ () can have. ls= ' ls ' echo $LS # single quotation marks do not parse the command completely, ignoring all special strings and outputting them as strings. ls= ' ls ' echo $LS # Double quotation marks are similar to single quotes, except that it is not so strict that there are 3 special characters in double quotes that cannot be ignored: $,\, ', that is, single quotation marks will interpret the special meaning of the string, while single quotes are used directly. ls= "ls" echo $LS # But if you use the eval command, the commands in double quotes are interpreted. ls= "ls" eval "$LS" set--1 2 3 4 #设置参数, the same as the 2 parameters in main C. While [$#-GT 0]# $ #代表参数总数doecho $ #输出第一个参数shift 1 #将参数个数减1, and all move to 1 one bit, you can also set 2, move 2 bits at a time, equivalent to I--, i is the total number of parameters. DONE#-GT greater than #-lt less than #-ge greater than or equal to #-le less than or equal to #-eq equals #-ne does not equal # in the script can be used $1,$2 ... to accept parameters, but there is another way to accept parameters, that is getopts. While getopts ABC opt #./main.sh-a-b-c can specify parameters and execute related commands docase $opt ina) echo "ABCD"; b) echo "1234";; c) echo "ABCD";; *) echo "* * * *"; Esacdone
Shell Summary (while)