I am using the following method in order to pass commands into a subshell that is started by "newgrp".
#!/bin/csh
echo "Before newgrp"
/usr/bin/newgrp users <<EONG
echo "hello from within newgrp"
id
EONG
echo "After newgrp"
It works fine as long as I don't try and "set" anything in the subshell.
i.e
#!/bin/csh
echo "Before newgrp"
/usr/bin/newgrp users <<EONG
echo "hello from within newgrp"
set a=npy
echo $a
id
EONG
echo "After newgrp"
As you can see above, I set a=npy inside the subshell and doing an echo $a should return npy. However, I get to see an error as a is not declared.
Can someone tell me how I can set env vars inside a subshell while using <<
$a
as\$a
to prevent it from being substituted by the shell before being passed as stdin tonewgrp
.