[Solved] newgrp creates a subshell!

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
User avatar
kent_dorfman766
Posts: 580
Joined: 2022-12-16 06:34
Location: socialist states of america
Has thanked: 74 times
Been thanked: 76 times

[Solved] newgrp creates a subshell!

#1 Post by kent_dorfman766 »

See the attached image description and then note the behaviour when executing the command. They don't match.
LOL

I want to temporarily set my GID value to "devel" so that when I run my IDE the output files are GID=devel, but I don't want my main user GID to default to devel.

The newgrp command spawns a subshell that must be exited when done. That causes me problems. I need the GID switch to occur in the current shell.

Am I going to have to hack the bash sourcecode or is there another way?

And yes, I understand the chmod g+s mechanism, but it only applies to directory heirarchies where it has been set.
Attachments
screen.jpg
screen.jpg (96.29 KiB) Viewed 161 times
Last edited by kent_dorfman766 on 2025-01-15 23:15, edited 1 time in total.

lindi
Debian Developer
Debian Developer
Posts: 628
Joined: 2022-07-12 14:10
Has thanked: 2 times
Been thanked: 128 times

Re: [Software] newgrp creates a subshell!

#2 Post by lindi »

As far as I know an unprivileged process cannot change its GID. You can see the logic at https://github.com/torvalds/linux/blob/ ... sys.c#L447 . You would need to have the CAP_SETGID capability which is almost the same as root already.

User avatar
kent_dorfman766
Posts: 580
Joined: 2022-12-16 06:34
Location: socialist states of america
Has thanked: 74 times
Been thanked: 76 times

Re: [Software] newgrp creates a subshell!

#3 Post by kent_dorfman766 »

lindi wrote: 2025-01-15 18:56 As far as I know an unprivileged process cannot change its GID. You can see the logic at https://github.com/torvalds/linux/blob/ ... sys.c#L447 . You would need to have the CAP_SETGID capability which is almost the same as root already.
Yeah. after writing a short test program, that was my take-away too. grumble grumble...

Post Reply