Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set 2 variables from 1 command

Status
Not open for further replies.

vodkadrinker

Technical User
May 16, 2002
163
GB
Is it possiable to set two variables from one awk command.

Here is an example of what I am trying to do.

Data file example: /tmp/oldpasswd
test:x:106:103::/home/test:/usr/bin/ksh
test2:x:106:103::/home/test2:/usr/bin/ksh
test3:x:106:103::/home/test3:/usr/bin/ksh

Script so far:
for i in `awk -F: '{print $1 $6 $7}' /tmp/oldpasswd`
do
useradd -d${HOMEDIR} -s$USERSH ${USER}
done

I would like to set variables from the awk line ie.
USER=$1
HOMEDIR=$6
USERSH=$7

so that I can run other checks before running the useradd command.

Any help would be appreciated, thanks VD

 
this sure NOT works.
get the list of user,first

for user in `sed -e 's/:.*//`
do
eval `awk "/^$user:/{ print export USER=$x HOME=$y...}"`
now USER HOME .. are exported
dothe job
done -----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
Found this script which does what I want

IFS=":"
cat /tmp/oldpasswd | while read line
do
set $line
useradd -c $5 -s /bin/bash -d /home/$1 $1
done
 
UUOC and improvement:

while IFS=":" read line
do
set $line
useradd -c "$5" -s /bin/bash -d /home/"$1" "$1"
done < /tmp/oldpasswd
vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
vodkadrinker: please formulate your questions correctly.
it was: Is it possible to set two variables from one awk command.
i understand this: is it possible to set more them 1 vars from a cmd ? yes it is.

in this case, your && vlad's reply are INAPPROPRIATE ! :(

-----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top