Unix C++
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Identify the error in the code

2 posters

Go down

Identify the error in the code Empty Identify the error in the code

Post by jennyinhere Tue Mar 02, 2010 6:44 pm

read $s
if [ $s -eq y ]
then
echo 'true'
else
echo 'false'
fi
----------------------
Error:

line 2: [: eq: unary operator expected
false

jennyinhere

Posts : 24
Points : 30
Join date : 2010-02-26
Age : 35

Back to top Go down

Identify the error in the code Empty Re: Identify the error in the code

Post by Christopher Tue Mar 02, 2010 6:57 pm

Code:
read s
if [ $s ="y" ]
then
echo true
else
echo false
fi


"-eq" can be used only to compare numerical data not a string.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum