E_BADARGS=65 if [ ! -n "$1" ] then echo "Usage: `basename $0` argument1 argument2 etc." exit $E_BADARGS fi echo index=1 for arg in "$*" do echo "Arg #$index = $arg" let "index+=1" done echo "Entire arg list as single word." echo index=1 for arg in "$@" do echo "Arg #$index = $arg" let "index+=1" done echo "Entire arg list as seperated words." echo index=1 for arg in $* do echo "Arg #$index = $arg" let "index+=1" done echo "Entire arg list as seperated words." echo index=1 for arg in $@ do echo "Arg #$index = $arg" let "index+=1" done echo "Entire arg list as seperated words." exit 0
执行结果:
$ ./test.sh bi yutong
Arg #1 = bi yutong
Entire arg list as single word.
Arg #1 = bi
Arg #2 = yutong
Entire arg list as seperated words.
Arg #1 = bi
Arg #2 = yutong
Entire arg list as seperated words.
Arg #1 = bi
Arg #2 = yutong
Entire arg list as seperated words
解析Shell脚本中参数处理
本文详细解析了Shell脚本中如何处理参数输入,包括单个参数、多个参数及参数列表的不同处理方式,以及参数在不同上下文中的输出表现。
1098

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



