如何逃脱bash脚本字符串 [英] How to escape strings in bash script

查看:100
本文介绍了如何逃脱bash脚本字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调用MySQL的bash脚本。密码北京时间无法正常传输,我想我必须逃避一些特殊的字符,如哈希或美元符号?


#!/斌/庆典USER = myuser的
PASS =#$为mypass#...调用的MySQL


解决方案

使用...已经是做了正确的事情,但 $ 需要转义( \\ $ ),如果它后面没有无效字。然而,你还需要确保始终有引号中的变量,以及,如:

  somecommand -p$ PASS

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

解决方案

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:

somecommand -p "$PASS"

这篇关于如何逃脱bash脚本字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆