Issue
echo "Enter Username"
read name
username = 'hagemaru'
if [ $name == $username ]
then
echo "Valid Username"
else
echo "Entered Username is invalid"
exit 1
fi
exit 0
Errors while executing:
l.sh: 3: username: not found
l.sh: 4: [: hagemaru: unexpected operator
Output should be:
Valid Username
Solution
You need to remove the space between username
and =
, otherwise bash will interpret username
as a command (as indicated in the error message) which doesn't exist. Doing this, you also need to remove the space between username=
and 'hagemaru'
as bash will interpret username= 'hagemaru'
as running the command username=
with a parameter of 'hagemaru'
which is not valid as there is no username=
command in bash.
echo "Enter Username"
read name
username='hagemaru'
if [ $name == $username ]
then
echo "Valid Username"
else
echo "Entered Username is invalid"
exit 1
fi
exit 0
Answered By - Mehdi Charife Answer Checked By - Terry (WPSolving Volunteer)