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
Also tried it, no luck. MYPASSWORD='password'"&"'123'
Any suggestions would be most helpful. Resetting the password on this website also seems problematic.
Just quote the parameter.
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.