[lug] newgrp and aliases
Zan Lynx
zlynx at acm.org
Wed Jan 16 14:36:34 MST 2013
On Wed, 2013-01-16 at 13:51 -0700, Davide Del Vento wrote:
> Folks,
> I want to change my default group on a Linux machine. I can't do it in
> /etc/passwd because that file gets generated automatically by a smart
> system which does not understand my needs and can't be changed (at
> least not in the very near future).
>
> Now I know that I can do it interactively with newgrp but that is
> inconvenient to remember to do at each login, so I thought to include
> it into my .bash_profile
> However that's proving harder than I thought, for the following reasons:
>
> 1) if I put newgrp at the beginning of .bash_profile the rest of the
> file is not executed (basically it stops executing bash profile and it
> spawn a new shell - if finishes executing bash profile when
> exiting....)
>
> 2) if I put newgrp (without the "-" argument) at the end of
> .bash_profile my aliases got lost in the spawning (and I still have to
> exit twice)
>
> 3) if I put newgrp (with the "-" argument) at the end of .bash_profile
> it enters into an infinite loop, spawning new shells forever (not too
> bad, CTRL-C stops the loop and it ends in a status I like, but now I
> have to "exit" several times to logout)
>
> So far the most convenient thing seems 3 (with a sleep to throttle
> it), but that seems really ugly and could go awry if I get distracted
> right before CTRL-C'ing and leave the infinite loop on the machine....
>
> Is there a better approach to solve this dilemma?
This looks like it covers the problem fairly well:
http://stackoverflow.com/questions/299728/how-do-you-use-newgrp-in-a-script-then-stay-in-that-group-when-the-script-exits
--
Knowledge Is Power
Power Corrupts
Study Hard
Be Evil
More information about the LUG
mailing list