Escape bash-special character in a bash string

Hi,

I am new in bash scripting. In my work, I provide support to several users and when I connect to their computers I use the same admin and password, so I am trying to create a script that will only ask me for the IP address and then connect to the computer without having me to type the user and password.

Here's the script:

read -p "Enter ip address: " IP_ADDRESS
pss="123@456"
open vnc://test:$pss@$IP_ADDRESS

If I remove the @ from my password I am able to connect with no issue. I have tried to escape the @ by adding a backslash before the character but still not working (e.g. 123\@456 ). Do you guys have any suggestions?..

Thanks in advance.

Just a suspicion: as @ is the separator between user info and target IP, it is inapt to be used inside the password. Are you dependent on it? Just remove it and try again.

Thanks for your reply, RudiC. The script works fine if the password does not contain the "@". The thing is that we have over 3,000 computers using a password with "@" for the admin account. Also, I would need to make a request to a different department that manages the computer images.. so it wouldn't be that simple to change the password :(...

@ works fine in BASH, it's your application that throws up. What exact application are you launching? Whose implementation of VNC on what system?

Since this looks like a URL, does it support URL encoding, i.e. could you put %40 instead?

2 Likes

It is working now :).. I replaced the "@" by %40 and I am able to connect with no problem.. I'm using this script to remote control Mac computers without typing the user and pass every time I need to connect to a computer. Thank you so much. This is going to be very useful for me. I really appreciate your help.

Best regards,

1 Like

Be aware that this means % characters could misbehave in your passwords, being taken as the beginning of % sequences.