[ale] Read multiple variables

Scott Plante splante at insightsys.com
Thu Sep 12 16:43:18 EDT 2013


Another alternative using just bash, and skipping awk altogether: 


( 
IFS=:; while read name pw uid gid comment shell; 
do 
[ "$name" = person ] && echo UID is $uid, GID is $gid and it\'s $comment; 
done < /etc/passwd 
) 


The parens keep IFS localized. You could also save it in another variable and reset it instead. 


Not sure if you're trying to match the username, but if so your grep should probably be 
grep "^person:" so you don't match that name in another user's comments or part of another user name 
i.e. user login "max" vs "maxwell" or comment "Account for max resources service". 


Scott 
----- Original Message -----

From: "leam hall" <leamhall at gmail.com> 
To: "Atlanta Linux Enthusiasts" <ale at ale.org> 
Sent: Thursday, September 12, 2013 8:35:05 AM 
Subject: [ale] Read multiple variables 








Well, I used to know how to do this. Trying to get multiple variables set in one line: 

while read UID GID COMMENT 
do 
echo UID is $UID, GID is $GID, and it's $COMMENT" 
done < grep person /etc/passwd | awk -F":" '{ print $3, $4, $5 }' 

Does not work well at all. Any ideas? 

Thanks! 

Leam 








-- 

Mind on a Mission 
_______________________________________________ 
Ale mailing list 
Ale at ale.org 
http://mail.ale.org/mailman/listinfo/ale 
See JOBS, ANNOUNCE and SCHOOLS lists at 
http://mail.ale.org/mailman/listinfo 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20130912/8fe6bb39/attachment.html>


More information about the Ale mailing list