1、使用参数$0可以确定shell从命令行启动的程序的名称,注意$0传递的是程序的完整路径,而不仅仅是程序的名称
例:
$cat test.sh
#!/bin/bash
#testing the $0 parameter
echo "The command entered is $0"
$./test.sh
The command entered is ./test.sh
$/home/yuan/test.sh
The commadn entered is /home/yuan/test.sh
如果想获取程序的名称,basename命令只返回程序名称,不带路径
$cat test.sh
#!/bin/bash
#testing the $0 parameter
name='basename $0'
echo "The command entered is $name"
$./test.sh
The command entered is test.sh
2、$#返回输入参数的个数
3、${!#} 返回最后输入的参数