文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>shell函数参数传递注意事项

shell函数参数传递注意事项

时间:2010-12-19  来源:xiaokaizi

传递给函数的参数严格按照空格进行划分,即使在同一个字符串内,除非显示使用引号进行包含。
funcArg.sh: execPrint() {     echo $@     echo "1th arg:$1"     echo "2th arg:$2" }
#脚本自身的参数 echo $1
str="helloA helloB" execPrint $str $1 execPrint "$str" $1
str="helloD" execPrint $1 $str

执行命令:sh funcArg.sh helloC   输出为: helloC helloA helloB helloC 1th arg:helloA         //为str的第一部分 2th arg:helloB         //为str的第二部分 helloA helloB helloC 1th arg:helloA helloB  //为str 2th arg:helloC helloC helloD 1th arg:helloC 2th arg:helloD
str中的空白会让函数execPrint将其拆分为不同的参数,虽然str作为一个整体,除非用双引号包含。 使用时一定要注意!
相关阅读 更多 +
排行榜 更多 +
贾达丛林冒险

贾达丛林冒险

休闲益智 下载
保卫薯片

保卫薯片

休闲益智 下载
云上剑行免费正版

云上剑行免费正版

角色扮演 下载