On Friday 13 July 2001 09:37 am, Chris G Haravata wrote:
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED]]On Behalf Of Brian Baquiran
> > Sent: Friday, July 13, 2001 9:30 AM
> > To: [EMAIL PROTECTED]
> > Subject: Re: [plug] readiing a line from a file and putting that in a
> > variable
> >
> > > Chris G Haravata wrote:
> > >
> > > haba ng subject line ano?  :)
> > >
> > > anyway, the problem is this:  i need to create a script which will
> > > automatically create user home directories from a file.  but i need to
> > > read the file first from within the script.  the file looks like the
> > > ff:
> > >
> > > /home/2000/abc-123455
> > > /home/1995/def-678901
> > > /home/2001/ghi-234567
> > > <etc until 1125 lines later>
> > >
> > > problem is:  is there a command to use which will read each line of
> > > the file and put the contents of that line in a variable?
> >
> > #!/bin/bash
> > for SOMEVAR in `cat somefile.txt`; do echo $SOMEVAR; done
>

an alternative is ala JCL script and data in one file

#!/bin/bash

while read varpath
do
        mkdir -v -p $varpath
done <<EOF
/home/2000/abc-123455
/home/1995/def-678901
/home/2001/ghi-234567
EOF

or

#!/bin/bash

cat <yourfile> | while read varpath
do
        mkdir -v -p $varpath
done


If it were something like the passwd file delimited by a ":" you can begin 
the script with an assignment of the IFS variable to change the delimiter 
from the default of white spaces (i.e. -  "<tab><space><newline>" ) and 
specify all the variables after the read.  If there are less variable names 
after the read than there are delimited in the file, the last variable name 
will get all the remaining characters in the current line being read.  

_
Philippine Linux Users Group. Web site and archives at http://plug.linux.org.ph
To leave: send "unsubscribe" in the body to [EMAIL PROTECTED]

To subscribe to the Linux Newbies' List: send "subscribe" in the body to 
[EMAIL PROTECTED]

Reply via email to