Programming and Scripting :: Little help needed



If you plan on using sed, you could use "s/ /\ /g"
If you plan on using a shell script, you could use IFS
(i.e.
IFS="
"
or use 'read')

Or you could just remember to never use spaces in filenames :P

I tried that sed command and it didn't worked.
I'm thinking It should be sed -e 's/ /\\ /g'. But I'm not sure about that.

Anyway. Everybody needs to sleep sometimes. And now is my time. :p
I'm thinking this over tomorrow.

Ah you're right, I forgot the double \\ for escape and that single quotes are needed for non-sub.
Quote (Zucca @ Jan. 30 2007,17:35)
I'm thinking It should be sed -e 's/ /\\ /g'. But I'm not sure about that.

Well It didn't. =D

I did like this:
Code Sample
echo "one two three" | sed -e 's/ /\\ /g'

It really printed: "one\ two\ three"
But if I had e file named "one two three" and I did this:
Code Sample
cat `echo "one two three" | sed -e 's/ /\\ /g'`

It would print an error message like this:
Quote
cat: one: No such file or directory
cat: two: No such file or directory
cat: three: No such file or directory

So cat still thinks that "one two three" is actually three seperate files.

while read line; do
commands
done < playlist

I still have very little idea of what you're trying to accomplish, but the above inputs lines literally.  The cat command should do the same, so I'm thinking there is a problem with the way poc or mpg321 is reading the input.  I have an mpg321 script that also didn't work with spaces in filenames, but wrapping the variable which represents the filename in quotes fixed the problem:

Code Sample
find ${DIR} | while read song; do
case "$song" in
*.mp3|*.Mp3|*.MP3) ${MP3_PLAYER} $@ "$song" && sleep 1 && clear;;
*.ogg|*.Ogg|*.OGG) ${OGG_PLAYER} $@ "$song" && sleep 1 && clear;;
esac;
done


Of course this runs a unique instance of mpg321 for each song rather than using a playlist, but the point is that I needed the filename in quotes.

Next Page...
original here.