标签:style blog http color ar 使用 for sp 文件
1 #!/bin/bash 2 3 # The differences between $* $@ "$*" "$@" 4 5 echo Dollar star is $* # 空格未保留 6 echo "Dollar star in double quotes is $*" # 引号内的空格被保留 7 echo Dollar at is $@ # 空格未保留 8 echo "Dollar at in double quotes is $@" #引号的空格被保留 9 10 echo 11 echo "Looping through Dollar Star" # 不引用$* 每个单词被当成独立的单词 12 for i in $* 13 do 14 echo "Parameter is $i" 15 done 16 17 echo 18 echo "Looping through Dollar Star with double quotes" # 使用"$*"整个参数列表被当成一个参数 19 for i in "$*" 20 do 21 echo "Parameter is $i" 22 done 23 24 echo 25 echo "Looping through Dollar At" # 不引用的#@与$*一样 26 for i in $@ 27 do 28 echo "Parameter is $i" 29 done 30 31 echo 32 echo "Looping through Dollar At in double quotes" # "$@"保留调用者的假设,引号内的作为一个参数,且保留空格 33 for i in "$@" 34 do 35 echo "Parameter is $i" 36 done
运行命令:
bash 01defaultParam.sh "hello world" two
执行结果:
对应新浪博客地址:http://blog.sina.com.cn/s/blog_6941438f0102v8qj.html
标签:style blog http color ar 使用 for sp 文件
原文地址:http://www.cnblogs.com/fengxm/p/4045741.html