如何在 bash 脚本中转义字符串
我正在运行一个调用 mysql 的 bash 脚本。密码未正确传输,我想我必须转义一些特殊字符,例如哈希或美元符号?
#!/bin/bash USER=myuser PASS="#mypass$" # ... call mysql
I am running a bash script that calls mysql. The password ist not correctly transmitted, I guess I have to escape some special chars, like the hash or the dollar sign?
#!/bin/bash USER=myuser PASS="#mypass$" # ... call mysql
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
"..."
已经是正确的做法,但如果不是,则需要转义$
(\$
) t 后跟一个“无效”字符。但是,您还需要确保始终将变量放在引号中,如下所示:Using
"..."
is already the correct thing to do, but the$
needs to be escaped (\$
) if it isn't followed by an "invalid" character. However you also need to make sure to always have the variable in quotation marks as well, as in:尝试在要转义的字符之前使用“\”。
Try to use "\" before the character that you are trying to escape.