Mun wrote:
> #! /bin/bash
> newgrp group1
> id -g -n             // This shows my login group ID, not group1

The 'newgrp' command spawns a new child shell.  After that child shell
exits the new group evaporates.  The rest of the script continues with
the previous id.  This is a common misunderstanding of how newgrp
works.  People often think it changes the current shell.  It does
not.  It stacks a child shell.

Basically, newgrp does not do what you thought it did.  It can't be
used in this way.

You might try having the newgrp shell read commands from a secondary
file.

  newgrp group1 < other-script-file

Or you might consider using 'sudo' or 'su' for that purpose too.

Bob

Reply via email to