Re: scripting problem
- From: Steve <Steve.DiSorbo@xxxxxxxx>
- Date: Mon, 28 Jan 2008 19:20:56 -0500
Try this, no file needed.
#!/bin/bash
/bin/ls -d1 /home/user/* |
while read NAMEDIR
do
echo $NAMEDIR
done
Wayne Betts wrote:
How about a construction like one of these two instead:
#!/bin/bash
/bin/ls -d1 /home/user/* > ls.out
cat ls.out | while read NAMEDIR
do
echo $NAMEDIR
done
OR
#!/bin/bash
/bin/ls -d1 /home/user/* > ls.out
while read NAMEDIR
do
echo $NAMEDIR
done < ls.out
BTW, the Internal Field Separator is set by the "IFS" environment variable. For instance, "IFS=:" is very useful for parsing passwd or shadow files.
-Wayne
Steven Buehler wrote:I am hoping that someone here can help me with this. I am running a little
script that backs up some directories for me. Below is snippet that gets me
into trouble.
---------------------
#!/bin/sh
DIRSTOBACKUP=`/bin/ls -d1 /home/user/*`
for NAMEDIR in ${DIRSTOBACKUP[@]}
do
echo $NAMEDIR
done
---------------------
The problem is that some of the directories have spaces in the names. When
running the for loop, it will take the new NAMEDIR at the space. So "Red
Hat" would end up listing as 2 directories, "Red" and "Hat". Any way around
this?
Thanks
Steve
--
Steve DiSorbo
System Programmer
Yale University ITS, AM&T Library Systems
Voice (203) 432-6694
Fax (203) 436-4067
steve.disorbo@xxxxxxxx
http://www.library.yale.edu/
--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
- References:
- scripting problem
- From: Steven Buehler
- Re: scripting problem
- From: Wayne Betts
- scripting problem
- Prev by Date: Re: scripting problem
- Next by Date: Error message is displayed.
- Previous by thread: Re: scripting problem
- Next by thread: Error message is displayed.
- Index(es):
Relevant Pages
- Re: scripting problem
... How about a construction like one of these two instead: ... cat ls.out
| while read NAMEDIR ... echo $NAMEDIR ... (RedHat) - RE: scripting problem
... for-loop and then again when you are inside the loop. ... for NAMEDIR
in $ ... backup the home directory. ... echo $NAMEDIR ... (RedHat)