newgrp
starts a subshell with the group you specified. So that line in your script will not finish until that subshell is done.
The handling of newgrp
is also different if you're using bash
or ksh
. ksh
implements it as a built-in command that is equivalent to exec /usr/bin/newgrp [group]
. So, like exec
, newgrp
never returns. (See some documentation here.)
If you want it to return, and want to execute commands in that subshell with changed group identity, you can use redirection.
For example:
#!/bin/ksh
echo "Before newgrp"
/usr/bin/newgrp users <<EONG
echo "hello from within newgrp"
id
EONG
echo "After newgrp"
Notice: /usr/bin/newgrp
is called explicitly to avoid the implicit exec
from ksh
. The last command in that script will run within the original shell, with the original group identity.