bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

for ... in ... do ignores escape characters


From: luiscolorado
Subject: for ... in ... do ignores escape characters
Date: Thu, 17 Apr 2008 13:21:35 -0700 (PDT)

Hello, everybody... I'm suffering a huge problem with the "for" command
because it wants to parse a variable ignoring escape characters.

For example, as you know, if I do something like this in bash:

for i in sony apple "hewlett packard"
do
echo $i
done

It will echo the following:

sony
apple
hewlett packard

However, I have a program that generates a list of files (let's say like the
previous one) that I want to use. This is what I get when some file names
have spaces:

for i in `my-program`
do
echo $i
done

It echoes the following:

sony
apple
hewlett 
packard


Did you notice how it broke "hewlett packard" in two separate strings? That
is, it uses the spaces to parse the file names!

I changed my program to add quotes, something like the following:

"sony"
"apple"
"hewlett packard"

Now the same snippet of code generates the following:

"sony"
"apple"
"hewlett
packard"

That is, it ignores the quotes! I also tried using \ to escape the spaces,
and I got something like the following:

sony
apple
hewlett\
packard

Any ideas?

Thanks a bunch!

Luis
-- 
View this message in context: 
http://www.nabble.com/for-...-in-...-do-ignores-escape-characters-tp16753925p16753925.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]