Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weird Problem??? 2

Status
Not open for further replies.

danhodges99

IS-IT--Management
Feb 6, 2003
21
GB
I have a problem I don't understand... I am trying to declare a variable, and then output the results of that variable, couldn't be simpler
#!/bin/ksh

VAR='Oranges'
if [ ${VAR}='Lemons' ]
then
echo "Found Lemons"
elif [ ${VAR}='Oranges' ]
then
echo "Found Oranges"
fi

The output shouold clearly be "Found Oranges", but it outputs "Found Lemons", or whatever is first in the if statement, it's doing my head in, please somebody help!
 
if [ "${VAR}" = "Lemons" ]

I would use double quotes, be sure to quote around the ${VAR}, and space around the = sign.
 
danhodges99,

You're missing the spaces between the variable and the equals sign and the equals sign and the string.

#!/bin/ksh

VAR='Oranges'
if [ ${VAR} = 'Lemons' ]
then
echo "Found Lemons"
elif [ ${VAR} = 'Oranges' ]
then
echo "Found Oranges"
fi

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top