









|
[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
[NMLUG] grep help
Sorry, make that:
groups ${user} | grep "[[:space:]]${grp}\([[:space:]]\|$\)"
-steve
----- Original Message -----
From: "Aaron NMLUG-EV" <aaron@boim.com>
To: "New Mexico Linux Users Group Mail List" <nmlug@nmlug.org>
Sent: Friday, March 18, 2005 6:46 AM
Subject: Re: [NMLUG] grep help
> On Wed, 2005-03-16 at 22:19, havoc wrote:
>> Ed Heron wrote:
>> > I'm writing a bash script that needs to check if a particular person
>> > is
>> > in a specific group.
>> >
>> > I'm using:
>> >
>> > if grep "^${group}:.*[:,]${user}[,$]" /etc/group >/dev/null ; then echo
>> > "${user} is a member of ${group}" ; fi
>> >
>> > Unfortunately, if $user is last in the list it appears to be false.
>> > If
>> > I `grep "^${group}:.*[:,]${user}$" /etc/group` it succeeds.
>> >
>> > I don't use many regexp, am I missing something?
>>
>> Looks like the square brackets are breaking '$' as a metacharacter. I
>> used alternation instead, and got success:
>
> So... might it be as simple as
> grep "^${group}:.*[:,]${user}[,\$]"
>
> aaron
>
>
> _______________________________________________
> NMLUG mailing list
> NMLUG@nmlug.org
> http://www.nmlug.org/mailman/listinfo/nmlug
>
|
|