On Sat, 25 Nov 2000, Mark Ivey wrote:
> Here are two more scripts, similar to the first 2:
> LIST=*; for NAME in $LIST; do echo "-->" $NAME; done
> LIST=$(\ls); for NAME in $LIST; do echo "-->" $NAME; done
>
> They give different output. The first one gives:
> --> Astral Projection
> --> Divinorum
> --> Fusion 19
> --> GoaArchive
> --> Starfire Records
>
> and the second one gives:
> --> Astral
> --> Projection
> --> Divinorum
> --> Fusion
> --> 19
> --> GoaArchive
> --> Starfire
> --> Records
>
>
> So, how do I get the second one to work like the first one? I've tried
> putting quotes around the filenames (\ls -Q), but it doesn't work. It
> still splits the names at the spaces. I will have other files alongside
> the directories later, so I can't just use the * version. Also, I know I
> could use the -exec flag on the find command, but I am having this problem
> with a few other for loops that I can't use find on, so I would really
> like to know how to get the for command to work. Thanks....
>
You can use $IFS to tell bash to split on just the line feeds instead of the
spaces....
[mloe@riverbank (1) bashtest]$ ls -l
total 0
-rw-rw-r-- 1 mloe mloe 0 Nov 26 18:42 nospace
-rw-rw-r-- 1 mloe mloe 0 Nov 26 18:42 one space
-rw-rw-r-- 1 mloe mloe 0 Nov 26 18:42 one two spaces
[mloe@riverbank (1) bashtest]$ IFS='
> '
[mloe@riverbank (1) bashtest]$ LIST=$(ls)
[mloe@riverbank (1) bashtest]$ for i in $LIST; do echo "-->$i<--"; done
-->nospace<--
-->one space<--
-->one two spaces<--
[mloe@riverbank (1) bashtest]$
I'm not sure though why you can't just use the first one? IF there are
going to be other fuiles you want to ignore you can use a more restrictive
patter than *. Arn't you just going ot have to do the same with thing with
ls anyway?.
Never the less... $IFS :)
M.
--
WebCentral Pty Ltd Australia's #1 Internet Web Hosting Company
Level 1, 96 Lytton Road. Network Operations - Systems Engineer
PO Box 4169, East Brisbane. phone: +61 7 3249 2583
Queensland, Australia. pgp key id: 0x900E515F
_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list