LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to put a string (w/ dbl & sgl quotes) into a pipe without it being changed ? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-put-a-string-w-dbl-and-sgl-quotes-into-a-pipe-without-it-being-changed-641974/)

lumix 05-13-2008 04:05 PM

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?

seraphim172 05-13-2008 05:24 PM

?
 
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

lumix 05-13-2008 05:52 PM

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.

chrism01 05-13-2008 06:00 PM

Have you tried double escape (\\) ?

rlhartmann 05-13-2008 06:05 PM

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

lumix 05-13-2008 06:29 PM

Quote:

Originally Posted by rlhartmann (Post 3152307)
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.

rlhartmann 05-13-2008 11:48 PM

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.

digvijay.gahlot 05-14-2008 01:33 AM

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

This might solve.

rlhartmann 05-15-2008 10:03 AM

Quote:

Originally Posted by digvijay.gahlot (Post 3152601)
$ 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.


All times are GMT -5. The time now is 06:05 AM.