why the script is not terminating with proper results

Hi everyone,
I am new to the linux.I wrote a small script and assigning two values to fname and lname and I want if the fname or lname are not given proper name like Toys or Gun the script should terminate and if they are given proper name it should execute.please help thanks:wall:

#!/bin/bash
fname=Toys
lname=Gun
y=VeryGood
x=Goodbye
echo "your first name please"
read fname
echo "Hello $fname, Lets be friend!"
echo "your last name Please"
read lname
echo "$lname,Lets work together!"
if
[ $fname=Toys ]
read fname
then
echo "$y"
 if
[ $lname=Gun ]
read lname
then
echo "$y"
else
echo "lets move next"
Exit
fi
else
Exit
echo "$x"
 fi

Statements in [ ] need to be spaced and quoted properly.
The 'if' has to be on the same line. The 'then' has to be on the next line or immediately after a ;

case is important. Don't capitalize "exit".

There's no point adding a command after exit. It won't ever be executed.

if [ "$fname" = something ]
then

I'm pretty sure you don't need to nest your if-statements 9-deep like that, either. If you find something wrong, just exit instead of slapping on another 'if'.

#!/bin/bash

echo "your first name please"
read fname

echo "your last name Please"
read lname

if [ "$lname" != "toys" -o "$fname" != "Gun" ]
then
        echo "Wrong name.  Goodbye!"
        exit 1
fi

echo "User $lname, $fname accepted"

thanks for the guidance- Appreciate for the help

---------- Post updated at 04:30 PM ---------- Previous update was at 04:08 PM ----------

one error i see after corona 688 wrote some comment and I executed the file at the end of the file it says "too many arguments" any clue

Please post your code, I can't tell what you did without it. The code I gave you works.

or with ksh:

#!/bin/ksh

read fname?'your first name please '

read lname?'your last name Please '

if [ "$lname" != toys -o "$fname" != Gun ]
then
        echo 'Wrong name.  Goodbye!'
        exit 1
fi

echo "User $lname, $fname accepted"
1 Like