the meaning of several symbols
$#: On behalf of the following parameters "number", the above table as an example of this shows as "4";
[email protected]: for "$" "$" "$" "$" "$4" means, each variable is independent (enclosed in double quotation marks);
$*: Represents "$1c$2c$3c$4", where C is a separator character and is preset to a blank key, so this example represents "$ $ $4".
Shift
[email protected] scripts]# VI sh08.sh
#!/bin/bash
echo "Total parameter number is ==> $#"
echo "Your whole parameter is ==> '[email protected]'"
Shift # makes the first "shift of a variable"
echo "Total parameter number is ==> $#"
echo "Your whole parameter is ==> '[email protected]'"
Shift 3 # "shift of three variables" for the second time
echo "Total parameter number is ==> $#"
echo "Your whole parameter is ==> '[email protected]'"
Results
[email protected] scripts]# sh sh08.sh One, three four five six #给予六个参数
Total parameter number is ==> 6 #最原始的参数情况
Your whole parameter is ==> ' one, three four five six '
Total parameter number is ==> 5 #第一次偏移, look underneath and find the first one missing.
Your whole parameter is ==> ' both three four five six '
Total parameter number is ==> 2 #第二次偏移掉三个, and both three four are missing.
Your whole parameter is ==> ' five six '
If ... then
if [conditional judgment one]; then
When the conditional judgment is established, the instruction work content can be carried out;
elif [conditional judgment Type II]; Then
when the conditional judgment two is established, the instruction work content can be carried out;
Else
When the conditional judgment one and two are not established, the instruction work content can be carried out;
fi
&& representative and;
| | represent or;
So, in the judgment of using brackets, && and | | are different from the state of the directive.
["$yn" = = "Y"-o "$yn" = = "Y"] can be replaced by ["$yn" = = "Y"] | | ["$yn" = = "Y"]
Case ... Esac
Case $ variable name in
"First variable content")
Program Segment
;;
"Second variable content")
Program Segment
;;
*)
other program execution segments that do not contain the contents of the first variable and the contents of the second variable
Exit 1
;;
Esac
function
function fname () {
Program Segment
}
Loops
While [condition]
Do
Program paragraph
Done
until [condition]
Do
Program paragraph
Done
For var in con1 con2 Con3 ...
Do
Program Segment
Done
For (initial value; limit value; execution step))
Do
Program Segment
Done
Shell script Basic syntax