Date: Thu, 17 May 2001 09:17:17 -0500 From: Lucas Bergman <lucas@slb.to> To: Don O'Neil <don@whtech.com> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Help w/ Awk Message-ID: <20010517091717.A634@billygoat.slb.to> In-Reply-To: <MOBBIPGJKBNNPGLGMFHFCEIFHCAA.don@whtech.com>; from don@whtech.com on Tue, May 15, 2001 at 07:08:10PM -0700 References: <20010516115758.L26110@welearn.com.au> <MOBBIPGJKBNNPGLGMFHFCEIFHCAA.don@whtech.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> That's a simpler way of doing it, but doesn't accomplish what I'm trying to > do. I'm trying to be able to loop through each user and get it's UID/GID and > do stuff... > > My problem wasn't with my AWK statement, but with my for/next loop. > > For whatever reason (still unknown), the for Line in Password was failing, > and was returning multiple lines, like there were EOL's embedded in the > lines. You're right. The shell assumes the argument to 'for' is a list, a string that it breaks into list elements at _any_ whitespace, not just newlines. So, if your /etc/passwd lines had whitespace in them (and they frequently do in the GECOS field), they would get broken in the middle. A previous response already pointed out a solution, passing the file to awk, which iterates over whole lines by default. You can use the shell's 'read' also: while read line; do # operate on "$line" done </etc/passwd See sh(1). Lucas To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010517091717.A634>