首页 > 代码库 > shell变量

shell变量

#!/bin/sh
echo -e “\$#(number of parameters):” $#
echo -e “\$0(program name):” $0
echo -e “\$1(first parameter):” $1
echo -e “\$2(second parameter):” $2
echo -e “\$@(all parameters):” “$@”
echo -e “\$*(show parameters):” $*
echo -e “\$\$(pid of this program):” $$
echo -e “\$?(show exit stat of previous program):” $?

 

shell>chmod u+x /tmp/test.sh

shell>/tmp/test.sh p1 -p2 –p3
$#(number of parameters):3
$0(program name):/tmp/test.sh
$1(first parameter):p1
$2(second parameter):-p2
$@(all parameters):p1 -p2 –p3
$*(show parameters):p1 -p2 –p3
$$(pid of this program):24063
$?(show exit stat of previous program):0

shell变量