bash:如何传递包含特殊字符的密码 [英] bash: how to pass password containing special characters
问题描述
我有一个bash脚本,可以从网站下载数据.为此,我需要使用网站的Java客户端传递用户名和密码.我的密码有一个引起问题的特殊字符.我已经尝试了通常的解决方案,但是都没有用.
I have a bash script to download data from a website. For this I need to pass the username and password using a java client for the website. My password has a special character that is causing problems. I have tried the usual solutions but none are working.
#!/bin/sh
#$ -cwd
MYPASSWORD='password&123'
java -jar client.jar -p username $MYPASSWORD file.gz
直接在命令中使用\或使用变量来尝试.但这没用.登录失败!
Tried using \ either directly in the command or using the variable. But that didnt work. Login failed!
MYPASSWORD=password\&123
java -jar client.jar -p username $MYPASSWORD file.gz
尝试使用"或".登录失败.
Tried "" or ''. Login failure.
MYPASSWORD='password&123'
java -jar client.jar -p username "\"$MYPASSWORD\"" file.gz
也尝试过,没有运气.MYPASSWORD ='密码'&"'123'
Also tried it, no luck. MYPASSWORD='password'"&"'123'
任何建议都是最有帮助的.在此网站上重置密码似乎也有问题.
Any suggestions would be most helpful. Resetting the password on this website also seems problematic.
推荐答案
只需引用参数即可.
mypassword='password&123'
java -jar client.jar -p username "$mypassword" file.gz
引号只是为了防止外壳程序在扩展参数后对 mypassword
的 value 进行任何进一步的处理.您实际上并没有将引号传递给您的程序.
The quotes are only there to keep the shell from performing any further processing of the value of mypassword
after the parameter is expanded. You don't actually pass quotes to your program.
这篇关于bash:如何传递包含特殊字符的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!