scripting problem

Roderick Derks redhat at r71.nl
Mon Jan 28 22:30:58 UTC 2008


IFS= InternalFieldSeperator. The value of $IFS is used by the script to seperate values from eachother.

See the difference if you use a colon 

[code]
IFS=:
var=":a::b:c:::"               # Same as above, but substitute ":" for " ".
output_args_one_per_line $var
#
# []
# [a]
# []
# [b]
# [c]
# []
# []
# []


You can temporarily change the value of the the IFS variable so that this doesn't happen.

[code]
ifs=$IFS
IFS='\
'
for NAMEDIR in ${DIRSTOBACKUP[@]}
do
echo $NAMEDIR
done
IFS=$ifs

Roderick


----- Original Message -----
From: "Steven Buehler" <steve at ibushost.com>
To: "General Red Hat Linux discussion list" <redhat-list at redhat.com>
Sent: 28 January 2008 22:23:04 o'clock (GMT+0100) Europe/Berlin
Subject: RE: scripting problem

How do you do that?  Never heard of that before.
Steve

> -----Original Message-----
> From: redhat-list-bounces at redhat.com [mailto:redhat-list-
> bounces at redhat.com] On Behalf Of Serge Dubrouski
> Sent: Monday, January 28, 2008 3:13 PM
> To: General Red Hat Linux discussion list
> Subject: Re: scripting problem
> 
> One way would be to set IFS (Internal Field Separator) to CR before
> your loop and restore it after it.
> 
> On Jan 28, 2008 2:00 PM, Aaron Bliss <abliss at brockport.edu> wrote:
> > Steve,
> > The easiest way to work around the space problem is to just use tar
> to
> > backup the home directory.
> >
> > Aaron
> >
> > 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
> > >
> > >
> >
> > --
> > Aaron Bliss
> > Systems Administrator
> > SUNY Brockport
> > (585) 395-2417
> >
> > --
> > redhat-list mailing list
> > unsubscribe mailto:redhat-list-request at redhat.com?subject=unsubscribe
> > https://www.redhat.com/mailman/listinfo/redhat-list
> >
> 
> 
> 
> --
> Serge Dubrouski.
> 
> --
> redhat-list mailing list
> unsubscribe mailto:redhat-list-request at redhat.com?subject=unsubscribe
> https://www.redhat.com/mailman/listinfo/redhat-list

-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request at redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list




More information about the redhat-list mailing list