Created
January 11, 2022 03:28
-
-
Save boltronics/5cf521b53d37112fe7eb8ed7e15c0b44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Add supplementary group permissions and update the shell prompt. | |
# Requires adding the following to .bashrc after PS1 has been set: | |
# if [ -n "${PS1_PREFIX}" ] | |
# then | |
# export PS1="${PS1_PREFIX}${PS1}" | |
# unset PS1_PREFIX | |
# fi | |
declare newsubgrp="${1}" | |
if [ -z "${newsubgrp}" ] | |
then | |
echo "Usage: $(basename ${0}) GROUP" 1>&2 | |
exit 1 | |
fi | |
if ! groups | cut -d ' ' -f 2- | grep -q "${newsubgrp}" | |
then | |
export NEWSUBGRP_OLDPS1="${PS1}" PS1_PREFIX="[${newsubgrp}] " | |
sg "${newsubgrp}" "newgrp "$(id -gn)"" | |
PS1="${NEWSUBGRP_OLDPS1}" | |
unset PS1_PREFIX NEWSUBGRP_OLDPS1 newsubgrp | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works like
newgrp
except adds a user to a subgroup so the user's GID is left untouched.Usage example: