linux – 如何使用特殊字符传递参数来调用shell脚本
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了linux – 如何使用特殊字符传递参数来调用shell脚本,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1407字,纯文字阅读大概需要3分钟。
内容图文
![linux – 如何使用特殊字符传递参数来调用shell脚本](/upload/InfoBanner/zyjiaocheng/952/a124f6598e074cd8865392cebb6e2cb2.jpg)
使用如下所需的参数调用.sh(shell脚本): –
sh home/example.sh --context_param dbUserName=username --context_param dbPassword=exam!ple##### --context_param resultDate=2017-01-13
使用参数dbUsername和password调用example.sh但是出现以下错误: –
-bash: !ple#####: event not found
我认为特殊字符限制命令执行.然后我如何传递特殊字符.任何帮助都会很明显.
解决方法:
改变线,
dbPassword=exam!ple#####
至,
dbPassword='exam!ple#####'
避免 ! (历史扩张)在bash中被特别对待
从QUOTING子节下的man bash,
When the command history expansion facilities are being used (see HISTORY EXPANSION below), the history expansion character, usually !, must be quoted to prevent history expansion.
在历史扩张下更多
History expansions are introduced by
the appearance of the history expansion character, which is ! by
default. Only backslash (\
) and single quotes can quote the history
expansion character.
此外,最好引用所有名称 – 值对以防止shell完成分词.
sh home/example.sh --context_param dbUserName="username" --context_param dbPassword='exam!ple#####' --context_param resultDate="2017-01-13"
关于分词,从手册页,
Word Splitting
The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quotes for word splitting. The shell treats each character of
IFS
as a delimiter, and splits the results of the other expansions into words using these characters as field terminators
内容总结
以上是互联网集市为您收集整理的linux – 如何使用特殊字符传递参数来调用shell脚本全部内容,希望文章能够帮你解决linux – 如何使用特殊字符传递参数来调用shell脚本所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。