天天看點

12 shell - 位置參數和特殊變量

$0  相當于C語言main函數的argv[0]
$1、$2...    這些稱為位置參數(Positional Parameter),相當于C語言main函數的argv[1]、argv[2]...
$#  相當于C語言main函數的argc - 1,注意這裡的#後面不表示注釋
$@  表示參數清單"$1" "$2" ...,例如可以用在for循環中的in後面。
$*  表示參數清單"$1" "$2" ...,同上
$?  上一條指令的Exit Status
$$  目前程序号
           
#! /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 $@"