Hi! the following function doesn't work and i've tried to figure out what the problem is but can't figure it out. thank you in advance for any help!
function modifyUserAssoc iation {
echo "Do you want to add a user to a group (1) or delete a user from a group (2)?"
read option
if [[ $option == 1 ]];
then
echo "Enter username"
read username
echo "Enter group name"
read group
fi
if grep -q "^${usernam e}:" /etc/passwd && grep -q "^${group}: " /etc/group;
then
sudo usermod -a -G $group $username
else
echo "Invalid username and group!"
fi
if [[ $option == 2 ]];
then
echo "Which user would you like to delete?"
read user
echo "And from which group?"
read group
if grep -q "^${usernam e}:" /etc/passwd && grep -q "^${group}: " /etc/group;
then
gpasswd -d $username $group
else
echo "Invalid username and group!"
fi
fi
if [[ $option != 1 && $option != 2 ]];
then
echo "Invalid input!"
fi
}
function modifyUserAssoc iation {
echo "Do you want to add a user to a group (1) or delete a user from a group (2)?"
read option
if [[ $option == 1 ]];
then
echo "Enter username"
read username
echo "Enter group name"
read group
fi
if grep -q "^${usernam e}:" /etc/passwd && grep -q "^${group}: " /etc/group;
then
sudo usermod -a -G $group $username
else
echo "Invalid username and group!"
fi
if [[ $option == 2 ]];
then
echo "Which user would you like to delete?"
read user
echo "And from which group?"
read group
if grep -q "^${usernam e}:" /etc/passwd && grep -q "^${group}: " /etc/group;
then
gpasswd -d $username $group
else
echo "Invalid username and group!"
fi
fi
if [[ $option != 1 && $option != 2 ]];
then
echo "Invalid input!"
fi
}
Comment