help with the script down here. I am so confuse as to why it is not working. I've change this thing back and forth and getting no where. It is driving me crazy. The error message keep saying script2: line 10: syntax error near unexpected token done' script2: line 10:done'

YORN="y"
while [ $YANSWER == "$YORN" ] do

echo " Do you want to add more user?(y/n)? "
read ANSWER
YANSWER=`echo $ANSWER | tr [:upper:] [:lower:] | cut -c 1`
    if [$YANSWER == "$YORN"]; then
        ./script2
    fi

done

You are missing a semicolon after the while construct.

while [ "$YANSWER" == "$YORN" ]; do

I'm sorry I didn't copy the whole script but here it is. I still am getting the error message here when I run it. If I put a semicolon between the bracket the do than the script just goes straight to the end after the word done.
./script2: line 37: syntax error near unexpected token done' ./script2: line 37:done'

    YORN="y"

    while [ "$YANSWER" = "$YORN" ] do

    echo "What is the users first name? "
    read FNAME
    echo "What is the users last name? "
    read LNAME
    echo "What is the users Initial group? "
    read IGROUP
    echo "What is the users Additional group? "
    read AGROUP

    UPFNAME=`echo $FNAME | tr [:lower:] [:upper:]`
    UPLNAME=`echo $LNAME | tr [:lower:] [:upper:]`
    LOWIGROUP=`echo $IGROUP | tr [:upper:] [:lower:]`
    LOWAGROUP=`echo $AGROUP | tr [:upper:] [:lower:]`
    ULNAME=`echo $LNAME | tr [:upper:] [:lower:] | cut -c 1-5`
    UFNAME=`echo $FNAME | tr [:upper:] [:lower:] | cut -c 1`
    UNAME="$ULNAME$UFNAME"

  useradd -c "$UPFNAME $UPLNAME" -g $LOWIGROUP -G $LOWAGROUP $UNAME
      echo 123456 | passwd --stdin $UNAME

    echo " Do you want to add more user?(y/n)? "
    read ANSWER
    YANSWER=`echo $ANSWER | tr [:upper:] [:lower:] | cut -c 1`
            if [$YANSWER == "$YORN"]; then
                    ./script2
            fi
    done

Well, first, you give an error condition reported at line 37 but the script you provide only has 31 lines. This makes it hard to know if what you have typed here accurately represents your true situation.

Here is a test script that behaves as I believe you want:

YANSWER="y"
YORN="y"
while [ "$YANSWER" == "$YORN" ]; do
    echo -n " Add another? (y/n): "
    read ANSWER
    YANSWER=`echo $ANSWER | tr [:upper:] [:lower:] | cut -c 1`
    if [ "$YANSWER" == "$YORN" ]; then
        echo "w00t"
    fi
done

When I run that I get the following:

$ bash t.sh 
 Add another? (y/n): y
w00t
 Add another? (y/n): y
w00t
 Add another? (y/n): n
$ 

Is that the expected behavior?

Thanks for getting back to me. This is it for the script. All I want is when the user answer yes, it opens the ./<script name> Again if the user answer no, it just exit the while loop.

Well, that is what my example does. Just change the echo "w00t" to whatever you want to happen on each iteration of the loop.

hey thank you very much, you are a great help. I have to modify the while loop and put in an if statement in there to get it working. Thank you

I'm not sure I understand your comment - is it not working the way it is presented? You shouldn't have had to insert anything to get the looping functionality...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.