LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 07-09-2003, 09:49 PM   #1
powerplane
LQ Newbie
 
Registered: Apr 2003
Location: P.R. China
Distribution: FreeBSD 4.8 stable
Posts: 26

Rep: Reputation: 15
How to compare these two strings in one line code?


How to compare these two strings in one line code?

$> md5 -q 4.8-RELEASE-i386-mini.iso
5f0d2576dbb56d6ec85d49ac9fa4bbf9

$> awk '/mini/ {print $4}' CHECKSUM.MD5
5f0d2576dbb56d6ec85d49ac9fa4bbf9

How to compare those two output string in a neat command?
 
Old 07-09-2003, 11:19 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Re: How to compare these two strings in one line code?

Quote:
Originally posted by powerplane
How to compare these two strings in one line code?

$> md5 -q 4.8-RELEASE-i386-mini.iso
5f0d2576dbb56d6ec85d49ac9fa4bbf9

$> awk '/mini/ {print $4}' CHECKSUM.MD5
5f0d2576dbb56d6ec85d49ac9fa4bbf9

How to compare those two output string in a neat command?
Code:
$> expr `md5 -q 4.8-RELEASE-i386-mini.iso` = `awk '/mini/ {print $4}' CHECKSUM.MD5`
Something like that?

Cheers,
Tink
 
Old 07-09-2003, 11:33 PM   #3
powerplane
LQ Newbie
 
Registered: Apr 2003
Location: P.R. China
Distribution: FreeBSD 4.8 stable
Posts: 26

Original Poster
Rep: Reputation: 15
Yeah!
It works !
Another question , can I use "test" or "[ ]" do the same job ?

$> test 33 = 44
nothing happened

$> [ 33 = 44 ]
nothing happened
 
Old 07-09-2003, 11:58 PM   #4
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 50
You have to check the command's exit status. . .
A simple way (simple minded too) is to do the following:
Code:
[ 33 -eq 33 ] && echo boo
[ 33 -eq 34 ] && echo boo
Since && only evaluates the second command if the first's exit status is 0 (33 = 33 is true => exit(0)).
There are better ways of checking, but I'm too tired to look through my scripts. . .

I'm an idiot, a very tired idiot, but still an idiot.
Code:
if [ 33 -eq 34 ]; then echo "boo"; fi
If you want strings, use "=" instead of "-eq", of course.

Last edited by moses; 07-09-2003 at 11:59 PM.
 
1 members found this post helpful.
Old 07-10-2003, 12:09 AM   #5
DrOzz
Senior Member
 
Registered: May 2003
Location: Sydney, Nova Scotia, Canada
Distribution: slackware
Posts: 4,185

Rep: Reputation: 60
and just because your not seeing any output, and the reasoning is behind what moses oringinally stated, your still not going to see any output with that line of code...just because 33 isn't equal to 34 so you won't see the output boo.....so instead of you responding and saying you still see no output, replace -eq with -ne just for you will see boo echoed back to you and you will finally be happy :P
 
  


Reply



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
[C]How to compare two strings w/o using strcmp() kponenation Programming 22 11-23-2005 08:29 AM
File reading line by line and compare Goni Linux - Software 14 09-21-2005 12:24 AM
Search and Replace with multiple-line strings ChristianNerds.com Programming 4 08-21-2005 02:32 PM
how to compare 2 text files by using php code antony_csf Programming 3 10-14-2004 05:52 AM
Using diff to compare file with common lines, but at different line numbers jimieee Linux - Newbie 3 05-10-2004 07:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration