[ale] Read multiple variables

Michael B. Trausch mbt at naunetcorp.com
Thu Sep 12 08:52:43 EDT 2013


On 09/12/2013 08:35 AM, leam hall wrote:
> 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 }'

I put this in a script and fixed it up to come up with this:

#!/bin/bash

grep "$1" /etc/passwd | awk -F":" '{ print $3, $4, $5 }' | \
    (
    while read _UID _GID _COMMENT
    do
    echo "UID is $_UID, GID is $_GID, and it's $_COMMENT"
    done
)

The ( ... ) construct runs the while loop in a subshell explicitly,
allowing the pipe before it to work.  I prepended _ to the variable
names because UID is a read-only shell variable.  Now you can save that
to a script and run it as "./script root" and it should come up with the
output for it.

    --- Mike

-- 
Naunet Corporation Logo 	Michael B. Trausch

President, *Naunet Corporation*
? (678) 287-0693 x130 or (855) NAUNET-1 x130
FAX: (678) 783-7843

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20130912/b7641f99/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: abfefgcj.png
Type: image/png
Size: 1701 bytes
Desc: not available
URL: <http://mail.ale.org/pipermail/ale/attachments/20130912/b7641f99/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 901 bytes
Desc: OpenPGP digital signature
URL: <http://mail.ale.org/pipermail/ale/attachments/20130912/b7641f99/attachment-0001.sig>


More information about the Ale mailing list