有很多特殊变量是被Shell自动赋值的,我们已经遇到了$?和$1,现在总结一下:
位置参数可以用shift命令左移。比如shift 3表示原来的$4现在变成$1,原来的$5现在变成$2等等,原来的$1、$2、$3丢弃,$0不移动。不带参数的shift命令相当于shift 1。例如:
#! /bin/sh echo "The program $0 is now running" echo "The first parameter is $1" echo "The second parameter is $2" echo "The parameter list is $@" shift echo "The first parameter is $1" echo "The second parameter is $2" echo "The parameter list is $@"
本文介绍了Shell中常用的特殊变量,如$0表示脚本名称,$1等为位置参数,$#为参数数量减一,$?获取上一条命令的状态码,$$为当前Shell的进程ID。还介绍了如何使用shift命令来改变位置参数。

被折叠的 条评论
为什么被折叠?



