Simple Script

Here is the script that i am trying to run. I get an error and i can't figure out what is the problem.
#!/bin/bash

echo "What is your name"
read NAME

if [ $NAME -eq $Eugene ]; then
echo "My name is the same"
esle
echo "You have a nice name"
fi

Whats u r error ?? R u declare the $Eugene value ?

Buddy,

The code is correct except that you have not declared the "Eugene" variable.
Hence its not able to compare the to variables so it might be throwing the error.
please use the below code:

#!/bin/bash

echo "What is your name"
read NAME
Eugene=Vicky
if [ $NAME -eq $Eugene ]; then
echo "My name is the same"
else
echo "You have a nice name"
fi

probably this would work. Please post the error if any....

I'll give it a shot and let you know.
Thanks.

I am new at this, how do you declair something as a value. Because with the last example I still get an error.

Try it like this...

#!/bin/bash

echo "What is your name"
read NAME
Eugene=Vicky
if [ "$NAME" = "$Eugene" ]; then
        echo "My name is the same"
else
        echo "You have a nice name"
fi
exit 0

Also just to point out the painfully obvious, you misspelled "else" ...

It would help if you posted the error message when you get one /-:

name: line 6: [: Eugene: unary operator expected
is the error.

Yes, that's because the variable Eugene is undefined or empty. You can put double quotes around the value to guard against this, or simply make sure it's always non-empty.

You should double-quote $NAME also, in case it's empty or contains special characters. In fact, always double-quote your variables.

Perderabo's script should work for you.

It works sort of. It skips the line "My name is the same"
Basically this should get an input from the user, if the name is the same as mine it should say "My name is the same" if it isn't it should say "You have a nice name"
As of now any name i put it echo's "You have a nice name"

Except Vicky, right?

haven't tried that name yet :slight_smile: