On Friday 13 July 2001 11:37 am, Chris G Haravata wrote:
> what is wrong with this?
>
> <-- start of script
>
> #!/bin/bash
> clear
>
> for SOMEVAR in `cat temp`
> do
>    usermod -d $SOMEVAR -m `cut -f5 -d/ temp`

Your are opening the temp file again and again inside the `cut`.  I haven't 
duplicated your script, but you will always start from the first record of 
"temp".

> done
>
> <-- end of script

As you probably want the cut to work only on the current line being read, 
you might like to try instead :

#!/bin/bash
clear

for SOMEVAR in `cat temp`
do
        USERID=`echo $SOMEVAR | cut -f5 -d/`
        usermod -d $SOMEVAR -m $USERID
done

exit 0

or

#!/bin/bash
clear

for SOMEVAR in `cat temp`
do
        usermod -d $SOMEVAR -m `basename $SOMEVAR`
done

exit 0


The following script may execute faster though, as fewer programs are started 
up:

# !/bin/bash
clear
IFS='/'

cat temp | while read dp1 dp2 dp3 dp4 userid
do
        usermod -d /$dp2/$dp3/$dp4 -m $userid
done 

exit 0

>
> where the contents of test file temp is:
>
> 1.   /tmp/home/2001/mco-100017
>      /tmp/home/2001/acc-100019
>      /tmp/home/1995/kap-100021
>
> 2.   `cut -f5 -d/ temp` is the username
> _
> 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]
_
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