网站设计制作要交印花税,上海做网站建设的公司,网络工具app,德州建设网站公司移动参数 bash shell 工具箱中的另一件工具是 shift 命令#xff0c;该命令可用于操作命令行参数。跟字面上的意思一样#xff0c;shift 命令会根据命令行参数的相对位置进行移动。 在使用 shift 命令时#xff0c;默认情况下会将每个位置的变量值都向左移动一个位置。因此该命令可用于操作命令行参数。跟字面上的意思一样shift 命令会根据命令行参数的相对位置进行移动。 在使用 shift 命令时默认情况下会将每个位置的变量值都向左移动一个位置。因此变量$3 的值会移入$2变量$2 的值会移入$1而变量$1 的值则会被删除。 注意:变量$0 的值也就是脚本名不会改变 例
$ cat shiftparams.sh
#!/bin/bash
# Shifting through the parameters
#
echo
echo Using the shift method:
count1
while [ -n $1 ]
doecho Parameter #$count $1count$[ $count 1 ]shift
done
echo
exit
$
$ ./shiftparams.sh alpha bravo charlie delta
Using the shift method:
Parameter #1 alpha
Parameter #2 bravo
Parameter #3 charlie
Parameter #4 delta
$
也可以一次性移动多个位置。只需给 shift 命令提供一个参数指明要移动的位置数即可
$ cat bigshiftparams.sh
#!/bin/bash
# Shifting multiple positions through the parameters
#
echo
echo The original parameters: $*
echo Now shifting 2...
shift 2
echo Heres the new first parameter: $1
echo
exit
$
$ ./bigshiftparams.sh alpha bravo charlie delta
The original parameters: alpha bravo charlie delta
Now shifting 2...
Heres the new first parameter: charlie
$