I want to change the working group in my script. So I wrote a line newgrp test_grp1 in my script. But my script is automatically exited after running this line. Are there any solution to overcome this problem?#/bin/ksh...newgrp test_grp1...Note: I am using Unix AIX OS.
Problem while running newgrp command in script
scripting;aix;group
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/kshecho Before newgrp/usr/bin/newgrp users <<EONGecho hello from within newgrpidEONGecho After newgrpNotice: /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.