LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-16-2009, 11:44 AM   #1
mwkemo
Member
 
Registered: May 2009
Location: Croatia
Distribution: Debian
Posts: 31

Rep: Reputation: 16
echo ' symbol


Hey,

I am having problem with echo command. It works, but ' symbol is removed from output, is there a way to fix this?

echo -n 'USE lgsl; INSERT INTO lgsl (ip, q_port, c_port, type) VALUES ('192.168.0.1', '30003', '30003', 'callofduty2');' > mysql.run

and after reading the mysql.run file there is no ' symbol. I did try to replace symbol with code \048' but this is not working for me. Propebly I'm doing something wrong but dont know what.

THX for help
 
Old 06-16-2009, 11:50 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Make the outer quotes be double quotes?
 
Old 06-16-2009, 12:01 PM   #3
mwkemo
Member
 
Registered: May 2009
Location: Croatia
Distribution: Debian
Posts: 31

Original Poster
Rep: Reputation: 16
No, this will not work as this command is used with other command that uses double quotas. Something like this

ssh admin@192.168.1.1:"cd test; echo -n "USE lgsl; INSERT INTO lgsl (ip, q_port, c_port, type) VALUES ('192.168.0.1', '30003', '30003', 'callofduty2');" > mysql.run; cd test2"

it is example, but it is not working if I am using the double quote. After "cd test" the script stops. If I remove double quotes after echo -n and use one quote then the script is working but it removes the quotes for '192.168.0.1', '30003', '30003', 'callofduty2' .And this quote needs to be there.

Last edited by mwkemo; 06-16-2009 at 12:03 PM.
 
Old 06-16-2009, 12:13 PM   #4
Dinithion
Member
 
Registered: Oct 2007
Location: Norway
Distribution: Slackware 14.1
Posts: 446

Rep: Reputation: 59
What about backslash?

echo This\' works for me.
 
Old 06-16-2009, 12:21 PM   #5
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 70
As Dinithion says, you have to use a backslash to escape it
 
Old 06-16-2009, 01:15 PM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Hello mwkemo

I don't use ssh so can't test but how about something like this ...

Code:
dquote='"'

ssh admin@192.168.1.1:"cd test; echo -n ${dquote}USE lgsl; INSERT INTO lgsl (ip, q_port, c_port, type) VALUES ('192.168.0.1', '30003', '30003', 'callofduty2');$dquote > mysql.run; cd test2"
AIUI, the mechanism is that the shell you are issuing the command from parses the line and creates a single word of everything between the " characters. Parsing removes the outer " characters and substitutes the $dquote variable so it now looks like

Code:
cd test; echo -n "USE lgsl; INSERT INTO lgsl (ip, q_port, c_port, type) VALUES ('192.168.0.1', '30003', '30003', 'callofduty2');" > mysql.run; cd test2
This is passed to another shell (on a remote system?) that parses it again. Parsing removes the outer " characters so it now looks like

Code:
cd test; echo -n USE lgsl; INSERT INTO lgsl (ip, q_port, c_port, type) VALUES ('192.168.0.1', '30003', '30003', 'callofduty2'); > mysql.run; cd test2
What we can't see in the code above is that the string from USE to ); is a single word, the argument for the echo -n command.

If this works and it's OK to have a space before USE lgsl in file mysql.run, you can simplify it by changing

Code:
echo -n ${dquote}USE
to
Code:
echo -n $dquote USE
Best

Charles
 
Old 06-16-2009, 02:21 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by mwkemo View Post
No, this will not work as this command is used with other command that uses double quotas.
http://www.catb.org/~esr/faqs/smart-...html#beprecise
 
Old 06-16-2009, 02:29 PM   #8
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
The quoting options for bash are quite simple, but double-quotes behave differently from single-quotes.

Put simply, double-quotes expands variables and allows you to escape special characters (like dollar signs and quotes) using a backslash, while single-quotes do not.

Single quotes just produce a literal string, and aren't very useful when you want to nest quotes, because you can't escape things. There is an alternative to escaping: if you leave no space between any two parameters, then they are run together as one (quoted or not). This is just an example, but you could use something like this to produce a single quote in parentheses (where the parentheses are single-quoted):
Code:
echo '('"'"')'
Note that a single quote is treated as a regular character when inside a double quotes, and so doesn't need escaping.


Your example uses BASH to launch another bash shell, and passes a single string to it that is then treated as a command, so you have to escape your quotes (by wrapping them in other quotes) in order to prevent them from being treated as ending quotes. This is called nesting strings.

To take your example, you could nest it using escaped double-quotes like this:
Code:
ssh admin@192.168.1.1 "cd test; echo -n \"USE lgsl; INSERT INTO lgsl
   (ip, q_port, c_port, type)
   VALUES ('192.168.0.1', '30003', '30003', 'callofduty2');\" > mysql.run; cd test2"
Hope that helps,

—Robert J Lee
 
Old 06-16-2009, 02:37 PM   #9
mwkemo
Member
 
Registered: May 2009
Location: Croatia
Distribution: Debian
Posts: 31

Original Poster
Rep: Reputation: 16
Thx for replay, unfortunatlly this is not working. I will c/p the command that I'm using. The problem is that I can't put double quotes inside first double quotes, if there is only one double quote symbol inside " " the script will stop. So there is no way that i can use double quotes in my command.

Code:
ssh -i /usr/local/gcp/userdata/sparta/sparta -f -o ConnectTimeout=1 -o PasswordAuthentication=no -o StrictHostKeyChecking=no -p 1111 sparta@192.168.0.1 "cd 192.168.0.1-30001; echo -n 'USE lgsl; INSERT INTO lgsl (ip, q_port, c_port, type) VALUES ('192.168.0.1', '30001', '30001', 'callofduty2');' > mysql.run; mysql -u gamecp_2 -h 192.168.0.1 -pabcde < mysql.run;"
If I put variable dquote='"' the script will stop to work in that place.
The /' is not working, I get some error message when i try to echo with /'

Maybe to replace the ' symbol with something else that echo command will output to file and after the echo creates the mysql.run file using the sed command to change to ' symbol. This will probably work but Iam looking for more simpler solution.
 
Old 06-16-2009, 02:51 PM   #10
mwkemo
Member
 
Registered: May 2009
Location: Croatia
Distribution: Debian
Posts: 31

Original Poster
Rep: Reputation: 16
rjlee,

THX for this tip, with \" the script is working and mysql.run file looks ok, it puts all ' symbols to file. The problem is solved.

Just out of curiosity, what if I need to put one more double quotes inside echo. For ex.

Code:
ssh admin@192.168.1.1 "cd test; echo -n \"USE lgsl; INSERT INTO "lgsl" (ip, q_port, c_port, type) VALUES ('192.168.0.1', '30003', 30003', 'callofduty2');\" > mysql.run; cd test2"
if I wrap around lgsl database name double qoutes. Will this work?

THX milion times

Last edited by mwkemo; 06-16-2009 at 03:17 PM.
 
Old 06-16-2009, 04:02 PM   #11
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
Quote:
Originally Posted by mwkemo View Post
Just out of curiosity, what if I need to put one more double quotes inside echo. For ex.

Code:
ssh admin@192.168.1.1 "cd test; echo -n \"USE lgsl; INSERT INTO "lgsl" (ip, q_port, c_port, type) VALUES ('192.168.0.1', '30003', 30003', 'callofduty2');\" > mysql.run; cd test2"
Well, you'd need to pass the double-quote character to the database name, like this:

Code:
ssh admin@192.168.1.1 "cd test;
echo -n \"USE lgsl; INSERT INTO \\\"lgsl\\\" (ip, q_port, c_port, type) VALUES
('192.168.0.1', '30003', 30003', 'callofduty2');\" > mysql.run; cd test2"
this will pass the actual string
Quote:
…INSERT INTO \"lgsl\"…
into the ssh session, which will pass the same string to the shell which invokes echo, which in turn will pass the double quotes as is to echo.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
symbol lookup error: /usr/lib/libavcodec.so.51: undefined symbol: av_crc04C11DB7 priceey Linux - Software 0 05-06-2009 08:14 AM
./firefox-bin :symbol lookup error:/lib/libgthread-2.0.so.0: undefined symbol: arulupsaras Linux - General 1 11-08-2008 04:48 AM
symbol lookup error: /usr/lib/libgtk-x11.2.0.so.0: undefined symbol:... IamI Slackware 17 02-29-2008 11:10 AM
Workaround: 'symbol lookup error: k3b: undefined symbol: lstat64' devdol Linux - Software 2 02-15-2008 03:36 AM
ls | echo, I got blank, why can't echo take the 2nd seat in a pipeline? elinuxqs Linux - Newbie 6 11-24-2006 08:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration