LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   BASH: if Variable -eq String not working (https://www.linuxquestions.org/questions/programming-9/bash-if-variable-eq-string-not-working-784444/)

worm5252 01-24-2010 02:59 PM

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

Code:

# 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
fi

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

./test.sh: 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?

Thanks

GrapefruiTgirl 01-24-2010 03: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 03: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 05:55 PM.