Re: Looking for command to compare two strings



On Sat, 2006-12-02 at 14:31 +0000, Paul Smith wrote:
On 12/2/06, Andy Green <andy@xxxxxxxxxxx> wrote:
Is there some command to automatically check whether the two following
strings are equal?

e64829764ecc434be937d92ab3a00f57
e64829764ecc434bg937d92ab3a00f57

[b]ash can do it easily enough, eg save this as say isequal

#!/bin/sh

if [ "$1" = "$2" ] ; then echo "same" ; else echo "different" ; fi


make sure you

chmod +x isequal

then you can go, eg

./isequal e64829764ecc434be937d92ab3a00f57 e64829764ecc434bg937d92ab3a00f57

You can use the guts of the script from the commandline, even better

if [ "`md5sum $1`" = "`md5sum $2`" ] ; then echo "same" ; else echo
"different" ; fi

Thanks, Andy. Is not there a native Linux command to compare strings?

Paul

It can be done from command line.
$ STR1="hello" ; STR2="world" ; if [ "$STR1" == "$STR2" ]; then echo
Match; else echo No match; fi
No match.
$ STR1="hello" ; STR2="hello" ; if [ "$STR1" == "$STR2" ]; then echo
Match; else echo No match; fi
Match

- Gilboa



--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list



Relevant Pages

  • Re: Looking for command to compare two strings
    ... Paul Smith wrote: ... Is there some command to automatically check whether the two following ... strings are equal? ... chmod +x isequal ...
    (Fedora)
  • string comparison not working
    ... command argument passed to the script as $1. ... echo "strings are identical" ... echo "strings are NOT identical" ...
    (comp.unix.shell)
  • string comparison not working
    ... command argument passed to the script as $1. ... echo "strings are identical" ... echo "strings are NOT identical" ...
    (comp.unix.misc)
  • Re: Persisting env vars in cmd windows
    ... more about batch files as you go on, ... echo The time is %time::=.% ... But the piece de resistance was the "start" command, ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)
  • Re: Persisting env vars in cmd windows
    ... But the piece de resistance was the "start" command, ... - Have all code for the one project in one single batch file. ... @echo off ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)