Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Syntax and Logical Errors are integrated in the following bash script. Fix the E

ID: 3880012 • Letter: S

Question

Syntax and Logical Errors are integrated in the following bash script. Fix the Errors or Rewrite the script to accomplish the task.

Task 3.3

Create a script to automatically read input and add user AND password (non encrypted), assuming logged in as root.

-----------------------------------------------------------------------------------------------------------------------

#!/bin/bash/

#

# The mkuser script was written by Dhillon

# to make my life a little easier.

#

echo "This program will add a new user."

echo "Type exit to quit."

echo -nn "Enter a new username: "

read name

while [ $names != "exit" ];

does

userad -d /home/$name -s /bin/bash $name

passwordd $name

echo -n " Type exit to quit or Enter a new username: "

read naeme

do

exit

Explanation / Answer

Hi Student,

There are couple of issues in the code snippet above :

1. looping issues, We need to allow the user to enter usernames until he/she enters exit

2. Terminating condition should have !="quit"

3. Few typo errors

4. useradd command

So below is the correct snippet after modification.

#!/bin/bash
echo "This program will add a new user."
while [[ $name != 'exit' ]] # while loop
do
echo "Enter a new user name."
echo "Type exit to quit."
read name # Ask the user to enter a string
useradd -d /home/$name -s /bin/bash $name
passwd $password
echo "Done"
done
exit

Happy Learning . If this answer enhances your skills please give a thumbs up! :)