- 论坛徽章:
- 0
|
set in shell script overrides to default value of position variables $1, $2, $3 ...
If you don't have set command in your shell script, $1 automatically takes the vaule of the first parameter you pasted to the shell script. $2 takes the second parameter and so on.
For example:
Your first script is script1.sh
- #!/bin/sh
- echo $1
- echo $2
复制代码 When you run it as: script1.sh start all , the shell will automatically assign $1=start and $2=all. The output of running this script is:
start
all
Your second script is script2.sh
- #!/bin/sh
- set `who -r`
- echo $1
- echo $2
复制代码 When you run it as: script2.sh start all , the output will be:
.
run-level
This is because the output of who -r command is something like:
. run-level 3 Aug 13 11:40 3 0 S
So now $1=. , $2=run-level, $3=3, $4=Aug, $5=13 ... and $1 is no longer start and $2 is no longer all any more. |
|