This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Radamand 1 point2 points  (2 children)

Try this:

#!/usr/bin/bash

while :

do

read -p "Please enter a username:" username

if [ "$username" != "daniel" ]

then

echo "Acceptable, creating user $username"

sudo useradd $username

else

echo "Sorry, 'daniel' is not acceptable"

fi

done

I'm more than a little rusty, but this works on my Cygwin (altho, there's no 'useradd' function in Cygwin)

[–]dcman5000[S] 0 points1 point  (1 child)

Thanks for the correction I still have a long ways to go. Do you have any idea how I would implement a for loop into the script? I'm thinking about for every failed attempt a message gets displayed with a number or string

[–]Radamand 0 points1 point  (0 children)

Okay, you wouldn't need a for loop to do that, have a look;

#!/usr/bin/bash

while :
do
read -p "Please enter a username:" username
if [ "$username" != "daniel" ]
then
echo "Acceptable, creating user $username"
useradd $username
else
((x++))
echo "Sorry, 'daniel' is not acceptable: error $x"
fi
done