LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 05-13-2008, 04:05 PM   #1
lumix
Member
 
Registered: Mar 2007
Distribution: Hardy (Gnome on Ubuntu 8.04) on Compaq N600c laptop
Posts: 323

Rep: Reputation: 30
How to put a string (w/ dbl & sgl quotes) into a pipe without it being changed ?


If I want to put:
Code:
"three's" > 4/5!
into a fifo pipe and have exactly the same come out, but without manually changing any characters (though adding characters to the beginning and end of this string would be okay), how can I do this?
 
Old 05-13-2008, 05:24 PM   #2
seraphim172
Member
 
Registered: May 2008
Posts: 101

Rep: Reputation: 15
?

Is this something you want to do in a shell script or in a C/C++ application?

I don't really understand the purpose of your project, but I would guess that you can send anything through a pipe, but to get meaningful results it all depends on the application at the receiving end of the pipe.

Linux Archive

Last edited by seraphim172; 06-25-2008 at 04:24 AM.
 
Old 05-13-2008, 05:52 PM   #3
lumix
Member
 
Registered: Mar 2007
Distribution: Hardy (Gnome on Ubuntu 8.04) on Compaq N600c laptop
Posts: 323

Original Poster
Rep: Reputation: 30
Any number of applications, but I use mplayer as an example.

I have the file:



Mplayer is running in slave mode and getting stdin from a fifo. Normally (i.e. without a fifo) you would run mplayer in slave mode, then type:

Code:
loadfile /home/user/music/Beck\ -\ \"Sea Change\"\ -\ it\'s\ all\ in\ your\ mind.aac
and it runs.

But now I have to put that string into a pipe, and bloody "echo" or some such bloody thing keeps de-escaping my quotes. I want to be able to do this in a script, so I can manually separate filenames at points with quotes in them. Or I could, but this would start to get very kludgey and bloated.

So, as posted, I want to send the above string into a fifo, and come out EXACTLY the same, escaped quotes and all.
 
Old 05-13-2008, 06:00 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Have you tried double escape (\\) ?
 
Old 05-13-2008, 06:05 PM   #5
rlhartmann
Member
 
Registered: Mar 2008
Posts: 73

Rep: Reputation: 16
Quote the whole string, then put backslashes in
front of the inner quotes and the exclamation.

$ mknod fifo p
$ echo "\"three's\" > 4/5\!" > fifo
 
Old 05-13-2008, 06:29 PM   #6
lumix
Member
 
Registered: Mar 2007
Distribution: Hardy (Gnome on Ubuntu 8.04) on Compaq N600c laptop
Posts: 323

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by rlhartmann View Post
Quote the whole string, then put backslashes in
front of the inner quotes and the exclamation.

$ mknod fifo p
$ echo "\"three's\" > 4/5\!" > fifo
Ah, but what if you're string contains a `\"' in it, like:

Code:
xxx'yyy\"zzz
I can't preserve the backslash it self. It keeps getting escaped. If I try to send:

Code:
echo "\"xxx'yyy\"zzz" > fifo
the `\"' gets de-escaped. If I should have a file with one double-quote in it, my script crashes. It's not likely to happen, of course, but I don't really want to find out the hard way when it does.
 
Old 05-13-2008, 11:48 PM   #7
rlhartmann
Member
 
Registered: Mar 2008
Posts: 73

Rep: Reputation: 16
Where is your data coming from? and how are you feeding
it to the FIFO?

You may need more than the two backslashes [I]chrism01]/I] suggested, at least
three \\ to escape the backslash, and \" to escape the quote.
 
Old 05-14-2008, 01:33 AM   #8
digvijay.gahlot
Member
 
Registered: Mar 2008
Posts: 53

Rep: Reputation: 15
$ mknod fifo p
$data='"three's" > 4/5!'
$ echo $data > fifo

This might solve.
 
Old 05-15-2008, 10:03 AM   #9
rlhartmann
Member
 
Registered: Mar 2008
Posts: 73

Rep: Reputation: 16
Quote:
Originally Posted by digvijay.gahlot View Post
$ mknod fifo p
$data='"three's" > 4/5!'
$ echo $data > fifo

This might solve.
You might want double quotes around $data
echo "$data" and echo $data can have very different results
on white space characters.
 
  


Reply



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
Problems with quotes and double quotes Andruha Slackware 6 01-02-2010 04:44 PM
pass a string to a named pipe sahel Programming 1 01-05-2006 07:52 PM
Using single quotes vs double quotes in PHP strings vharishankar Programming 6 07-11-2005 11:41 AM
Trouble on PHP & MySQL Quotes Gerardoj Programming 0 05-26-2004 09:48 PM
Replace a string including simple quotes. philipina Programming 4 03-18-2004 08:01 AM

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

All times are GMT -5. The time now is 09:02 PM.

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