linux中预留的$变量
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
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。