LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 01-24-2010, 02:59 PM   #1
worm5252
Member
 
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

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
 
Old 01-24-2010, 03:04 PM   #2
GrapefruiTgirl
Guru
 
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, 03:07 PM   #3
worm5252
Member
 
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.
 
  


Reply

Tags
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 03:54 AM
[SOLVED] Bash scripting, separating variable from string text emmalg Linux - Newbie 3 06-26-2009 03:31 AM
Bash variable problem: cURL -b parameter (string form e.g. "name=value;n2=v2") sithemac Other *NIX 3 07-09-2008 06:15 PM
extract string from file to variable [BASH] NikosNL Programming 13 05-07-2008 09:43 AM
Bash variable string expansion Reginald0 Linux - Software 5 02-13-2007 10:38 AM


All times are GMT -5. The time now is 11:32 PM.

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