导读
在本文中讨论的一些shell特殊参数是:$*,$@,$#,$$,$!
示例1:使用 $*和$@ 来扩展位置参数
本实例脚本中使用$*和$@参数:
[root@localhost scripts]# vim expan.sh
#!/bin/bash
export IFS='-'
cnt=1
# Printing the data available in $*
echo "Values of \"\$*\":"
for arg in "$*"
do
echo "Arg #$cnt= $arg"
let "cnt+=1"
done
cnt=1
# Printing the data available in $@
echo "Values of \"\$@\":"
for arg in "$@"
do
echo "Arg #$cnt= $arg"
let "cnt+=1"
done
下面是运行结果:
[root@localhost scripts]# ./expan.sh "Hello world" 2 3 4
Values of "$*":
Arg #1= Hello world