There's a missing if after
Code:
if [“$RESPONSE” = "a"]; then
#Create Users
echo "What is your NAME?"
read NAME
if [“$NAME” -!= "Tiara"]; then
echo "Your name is $NAME"
useradd -c $NAME
else
echo "That's my name too."
fi
46 of the double quotes are sloping double quotes instead of straight.
As already pointed out, -!= should be !=
In the Create Links and File Permissions sections the variables are not initialised before use.
As already pointed out, a case statement would be much better than all those ifs but maybe this exercise comes in the course before the case statement has been introduced and will be modified to use case later -- cleverly showing the student how much neater a case based solution is.
The script should exit after the "please try again" errors or the user does ot have an opportunity to try again.
Error messages are conventionally written to stderr, not echo's default stdout. Maybe this convention has not been introduced yet.
A function to test directory existence and create a directory would be much neater. Maybe functions have not been introduced yet.
EDIT:
The Create Links section does not have a ln command (the first ls should be ln -s ?)
Debugging would be easier if the commands were only displayed, not executed. This could be done by using a $debug variable as shown below (change to debug= when debugged).
Code:
#!/bin/bash
#Individual Project 5 for UNIX CS126
#Create a Menu
echo "Choose an option
a. Create Users
b. Create Groups
c. Create Directories
d. Create Links
e. Set File Permissions
f. exit"
read RESPONSE
echo "DEBUG: RESPONSE is '$RESPONSE'"
debug=echo
if [ "$RESPONSE" = "a" ]; then
#Create Users
echo "What is your NAME?"
read NAME
if [ "$NAME" != "Tiara" ]; then
echo "Your name is $NAME"
$debug useradd -c $NAME
else
echo "That's my name too."
fi
fi
#Create Groups
if [ "$RESPONSE" = "b" ]; then
echo "What is the name of the GROUP?"
read GROUP
if test -g $GROUP; then
echo "That group name exists, please try again."
else
echo "The name of the group is $GROUP."
$debug groupadd $GROUP
fi
fi
#Create Directories
if [ "$RESPONSE" = "c" ]; then
echo "What is the name of the DIRECTORY1?"
read DIRECTORY1
if test -d $DIRECTORY1; then
echo "That directory name exists, please try again."
else
echo "The name of the directory is $DIRECTORY1."
$debug mkdir $DIRECTORY1
ls -l
echo "What is the name of the DIRECTORY2?"
read DIRECTORY2
if test -d $DIRECTORY2; then
echo "That directory name exists, please try again."
else
echo "The name of the directory is $DIRECTORY2."
$debug mkdir $DIRECTORY2
ls -l
echo "What is the name of the DIRECTORY3?"
read DIRECTORY3
if test -d $DIRECTORY3; then
echo "That directory name exists, please try again."
else
echo "The name of the directory is $DIRECTORY3."
$debug mkdir $DIRECTORY3
ls -l
echo "What is the name of the DIRECTORY4?"
read DIRECTORY4
if test -d $DIRECTORY4; then
echo "That directory name exists, please try again."
else
echo "The name of the directory is $DIRECTORY4."
$debug mkdir $DIRECTORY4
ls -l
fi
fi
fi
fi
fi
#Create Links
if [ "$RESPONSE" = "d" ]; then
echo "Links all directories together."
cd $DIRECTORY1
ls $DIRECTORY2_ln $DIRECTORY3_ln $DIRECTORY4_ln
ls
fi
#File Permissions
if [ "$RESPONSE" = "e" ]; then
echo " This will modify permissions."
$debug usermod -g $GROUP $NAME
groups $NAME
$debug chown $NAME $DIRECTORY1
ls -l
$debug chmod u+x, g+w $DIRECTORY1
$debug chmod u+x, g-r, o-r $DIRECTORY2
$debug chmod u+x, g-r, o-r $DIRECTORY3
$debug chmod u+x, g-r, o-r $DIRECTORY4
ls -l
fi