Escape bash-special character in a bash string


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 2 Weeks Ago
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:
Code:
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.




Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 2 Weeks Ago at 03:18 AM.. Reason: Added CODE tags.
# 2  
Old 2 Weeks Ago
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.
# 3  
Old 2 Weeks Ago
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 Smilie...

Last edited by arcoa05; 2 Weeks Ago at 11:29 AM..
# 4  
Old 2 Weeks Ago
@ 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?
These 2 Users Gave Thanks to Corona688 For This Post:
arcoa05 (2 Weeks Ago) wisecracker (2 Weeks Ago)
# 5  
Old 2 Weeks Ago
It is working now Smilie.. 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,
This User Gave Thanks to arcoa05 For This Post:
Corona688 (2 Weeks Ago)
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Bash - Inserting non printable character(s) in string variable jcdole Shell Programming and Scripting 6 12-18-2015 07:19 AM
Bash: Pulling first and last character in string petfyp Shell Programming and Scripting 5 12-12-2015 07:07 AM
Match string against character class in bash urello Shell Programming and Scripting 5 03-07-2014 05:24 PM
Escape special character arindam guha UNIX for Advanced & Expert Users 9 04-26-2013 11:25 AM
Escape special character sandy162 Shell Programming and Scripting 2 04-17-2013 02:18 PM
How to replace with a special character in String nanthagopal Shell Programming and Scripting 5 08-23-2012 12:52 PM
Regex escape special character in AWK if statement purebc Shell Programming and Scripting 4 05-15-2012 09:28 AM
Bash: How to remove the last character of a string? LessNux Shell Programming and Scripting 12 02-18-2012 02:27 PM
Bash - get specific character from the string xqwzts Shell Programming and Scripting 2 02-13-2012 12:57 PM
awk not escape my bash variable winggundamth Shell Programming and Scripting 2 08-09-2011 01:57 PM
'watch' not interpreting escape codes in bash script Arashi Shell Programming and Scripting 1 07-20-2010 06:52 AM
bash curl escape & in url unclecameron Shell Programming and Scripting 4 05-20-2010 03:33 PM
Printing special character in bash sentinel Shell Programming and Scripting 6 01-04-2010 04:25 AM
bash script to check the first character in string ole111 Shell Programming and Scripting 2 03-19-2008 12:34 AM
replacing string with special character ??? imppayel Shell Programming and Scripting 4 12-08-2004 04:07 AM