gahh I'm confused. I was under the impression that I was incrementing the value which then dictates which line to read from the file.
the code you've said I should use, could you possibly help me in terms of what I need to replace if I put that in and where etc?
Sorry I'm just so new to shell scripting, total noob.
---------- Post updated at 08:17 PM ---------- Previous update was at 07:09 PM ----------
I have managed to integrate your suggestion Jerry thanks a lot for the help but it's brought up another issue now, maybe simply fixed but I can't get my head around it.
This is my code now:
Quote:
useradd () {
while read eachline
do
existinguser=$(find /home -name $eachline)
if
[ -s $existinguser ]
then
sudo useradd -m $eachline
else
userexists
fi
done < Usernames
}
userexists () {
echo "PRESS 1 TO DELETE THE OLD $existinguser ACCOUNT, OR 2 TO KEEP IT, BUT RENAME IT WITH _OLD PREFIX:"
read input
echo $input
if [ $input -eq '1' ]
then
user=$(basename $existinguser)
sudo userdel $user
sudo rm -rf $existinguser
echo "USER ACCOUNT DELETED"
sudo useradd -m $user
unset username
unset existinguser
unset user
elif [ $input -eq '2' ]
then
suffix="_old"
user=$(basename $existinguser)
sudo userdel $user
sudo mv /home/$user /home/$user$suffix
echo "USER ACCOUNT NAME SUFFIXED WITH _OLD"
sudo useradd -m $user
unset username
unset existinguser
unset user
fi
useradd
}
useradd
The script successfully creates user accounts for names of accounts that don't already exist but when the userexists () function is called it throws up an infinite loop error message that says,
Quote:
./makeUser1: 28: [: /home/shaun: unexpected operator
PRESS 1 TO DELETE THE OLD /home/shaun
/home/charlie/.local/share/Trash/files/shaun ACCOUNT, OR 2 TO KEEP IT, BUT RENAME IT WITH _OLD PREFIX:
ellis
./makeUser1: 45: [: Illegal number: ellis
./makeUser1: 55: [: Illegal number: ellis
If anybody can help me fix this issue it would be much appreciated!
thank's in advance again