Re: OT: shell scripting problem

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

 



On Tue, May 17, 2005 at 06:33:30PM -0500, linux.whiz@xxxxxxxxx wrote:
> On 5/17/05, kevin.kempter@xxxxxxxxxxxxxxxxx
> <kevin.kempter@xxxxxxxxxxxxxxxxx> wrote:
> > On Tuesday 17 May 2005 16:55, linux.whiz@xxxxxxxxx wrote:
> > > My brain is fried.  I know there is a simple answer to this but I'm
> > > drawing a blank.  I want to run a script against the contents of a
> > > text file.  The text file is just my users' first name, middle initial
> > > and last name like this:
> > >
> > > John A Smith
> > > Mary P James
> > > Sally R Jones
> > > Fred Q Davis
> > >
> > > What I want to do is for each user in this file, run a script.  I
> > > tried to do this:
> > >
> > > for i in `cat textfile`; do
> > >   myscript.sh $i
> > > done
> > >
> > > I expect this to run like this:
> > >
> > > myscript.sh John A Smith
> > > myscript.sh Mary P James
> > > myscript.sh Sally R Jones
> > > myscript.sh Fred Q Davis
> > >
> > > Instead it runs like this:
> > >
> > > myscript.sh John
> > > myscript.sh A
> > > myscript.sh Smith
> > > ...
> > > etc.
> > >
> > > How do I get this script to run correctly?
> > >
> > > Thanks!
> > > LW
> > 
> > You get this behavior because the internal field separator by default
> > recognizes spaces, tebs, etc as field separators.
> > 
> > Try this instead (where names.lst is your file of names):
> > 
> > exec < ./names.lst
> > while read line
> > do
> >         myscript.sh $line
> > done

while read FIRST MI LAST
do
        myscript.sh $FIRST $MI $LAST
done < ./names.lst

The read will assign to as many variables as are on the read, according to the
IFS value.  The last variable gets whatever is left. 


> As soon as I issue the exec < ./names.lst command, my shell exits.  My
> understanding is that exec takes over the PID of the current process,
> so when you try to exec a text file it makes sense that the process
> would exit.
> 
> Other ideas?
> 
> -- 
> fedora-list mailing list
> fedora-list@xxxxxxxxxx
> To unsubscribe: http://www.redhat.com/mailman/listinfo/fedora-list

-- 
============================================================================
Neal Rhodes                    MNOP Ltd                       (770) 972-5430
President                  4737 Habersham Ridge         fax:  (770) 978-4741
                          Lilburn (atlanta) GA 30047    


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux