Parameter count
Special Variable $ #可以存储执行脚本时包含的命令行参数个数!
#!/bin/bash
If [$#-ne 2]
Then
Echo Usage:input a B
Else
Total=$[$ + $]
echo the total is $total
Fi
[Email protected] ~]#./test33.sh 3 4
The total is 7
****************************************************
When you want to get the $ #参数的最后面那个参数时, you can use the ${!#} command
#!/bin/bash
params=$#
echo the toal parameters is $params
echo the last parameters is ${!#}
[Email protected] ~]#/test34.sh 3
The Toal parameters is 1
The last parameters is 3
****************************************************
Get all data
$* all arguments provided on the command line as a single word that contains each parameter value that appears on the command line
[email protected] handles all the arguments in the command line as multiple words in the same string
#!/bin/bash
#testing $* and [email protected]
echo "Using The \$* method: $*"
echo "Using the \[email Protected] method: [Email protected]"
Count=1
For parm in "$*"
Do
echo "\$* Parameters # $count = $parm"
count=$[$count + 1]
Done
Count=1
For parm in "[email protected]"
Do
echo "\[email protected] Parameters # $count = $parm"
count=$[$count + 1]
Done
[Email protected] ~]#/test35.sh Jack Tom bot luck haha
Using the $* method:jack Tom bot luck haha
Using the [email protected] method:jack Tom bot luck haha
$* Parameters #1 = Jack Tom bot luck haha
[Email protected] Parameters #1 = Jack
[Email protected] Parameters #2 = Tom
[Email protected] Parameters #3 = bot
[Email protected] Parameters #4 = Luck
[Email protected] Parameters #5 = haha
$*: As a word
[Email protected]: treat each parameter separately
Special parameter variables in Linux