meallhour
meallhour

Reputation: 15581

Updating /etc/group with a new group ID

I want to update group name within /etc/group with a new group ID.

Suppose /etc/group has an entry such as group1 345.

When I run the script ./grp.sh group1 356 then it should update /etc/group with value group1 356.

I have written the following script grp.sh but it not working. some issue with grep -q "^$1:[^:]*:$2:

   #!/usr/bin/env bash
    grep -q "^$1:[^:]*:$2:" /etc/group || /usr/sbin/groupmod -g "$2" "$1"

Upvotes: 0

Views: 268

Answers (1)

agc
agc

Reputation: 8406

The grep -q "^$1:[^:]*:$2:" /etc/group || doesn't appear to be needed. This alone should work:

#!/usr/bin/env bash
/usr/sbin/groupmod -g "$2" "$1"

Upvotes: 1

Related Questions