Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


Search this Thread
Old 01-24-2010, 03:59 PM   #1
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX
Posts: 565

Rep: Reputation: 57
Question 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?

Old 01-24-2010, 04:04 PM   #2
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
In the context in which you are using this code, the -eq operator is expecting integers. Just use an = sign instead.
Old 01-24-2010, 04:07 PM   #3
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX
Posts: 565

Original Poster
Rep: Reputation: 57
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.


bash, if, string, variable

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash search for a pattern within a string variable nutthick Programming 7 03-06-2012 04:54 AM
[SOLVED] Bash scripting, separating variable from string text emmalg Linux - Newbie 3 06-26-2009 04:31 AM
Bash variable problem: cURL -b parameter (string form e.g. "name=value;n2=v2") sithemac Other *NIX 3 07-09-2008 07:15 PM
extract string from file to variable [BASH] NikosNL Programming 13 05-07-2008 10:43 AM
Bash variable string expansion Reginald0 Linux - Software 5 02-13-2007 11:38 AM

All times are GMT -5. The time now is 04:33 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration