#!/bin/bash
echo "Enter username: "
read username
sudo useradd "$username"
read -p "add to wheel group $username $foo? [yn]" answer
if [[ $answer = y ]] ; then
sudo usermod -aG wheel "$username" && echo "$username is added to wheel group"
else echo "$username is not in wheel group"
fi
read -p "add password to $username $foo? [yn] " answer
if [[ $answer = y ]] ; then
passwd $username
else echo "no passwd set to user $username"
fi
read -p "change user to $username $foo? [yn]" answer
if [[ $answer = y ]] ; then
su $username && pwd
else echo "user not changed to $username"
fi
in this part i am trying to change to a new user and run pwd. but script stops executing right after su $username. i want to run several commands inside a new user.
read -p "change user to $username $foo? [yn]" answer
if [[ $answer = y ]] ; then
su $username && pwd
else echo "user not changed to $username"
fi
script could be more clear but i just want to be able to run script that would continuously run in new user