-   Programming (
-   -   BASH: if Variable -eq String not working (

worm5252 01-24-2010 03:59 PM

BASH: if Variable -eq String not working
Here is the code in question


# Determine which release of Debian is
# being used.
CODENAME=`lsb_release -c`

# Backup /etc/apt/sources.list
mv /etc/apt/sources.list /etc/apt/sources.list.bak

# Install the correct /etc/apt/sources.list
# file.
LENNY='Codename:      lenny'

if [ "$CODENAME" -eq "$LENNY" ] ; then
        cp $SRCDIR/files/aptsources/lenny /etc/apt/sources.list

How ever when I run this script I get the following error

./ line 57: [: too many arguments
Line 57 is the line that reads if [ "$CODENAME" -eq "$LENNY" ] ; then

I just don't get it, I have racked my brain trying to figure out every combination of how I should write this if statement and I can't get it to work. What am I doing wrong and why is it wrong?


GrapefruiTgirl 01-24-2010 04:04 PM

In the context in which you are using this code, the -eq operator is expecting integers. Just use an = sign instead.

worm5252 01-24-2010 04:07 PM

DOH! It is always something simple. Thanks for pointing that out. Sometimes you just don't see the simplest errors and need a 2nd set of eyes.

All times are GMT -5. The time now is 10:09 PM.