Mostly Linux & Python syntax notes and hyperlinks.

Monday, June 28, 2010

Linux: Testing for string equality in ksh

In .ksh this is how to do it:
$ plex="SIMPLEX"
$ if [ "$plex" = "SIMPLEX" ]
> then
> echo y
> fi
y
$ if [ "$plex" = "DU" ]
> then
> echo y
> else
> echo n
> fi
n

All of these do not work:
$ plex="SIMPLEX"
$ if (($plex=="SIMPLEX"))
> then
>   echo y
> else
>   echo n
> fi
y
$ if  (($plex=="DUP")) then echo t
> fi
t
$ if (($plex="SIMPLEX"))
> then
>   echo y
> else
>   echo n
> fi
n
$ if [["$plex"=="SIMPLEX"]]
> then
>   echo yes
> fi
ksh: [[SIMPLEX==SIMPLEX]]: not found
$ if [$plex="SIMPLEX"]
> then
>   echo yes
> fi
ksh: [SIMPLEX=SIMPLEX]: not found

1 comment:

  1. If I've said it once, I've said it a thousand times: Margie H is a true Renaissance Woman!

    That being said, I still think she should get the pink, plaid Netbook at Best Buy...

    Karl runge@karlrunge.com

    ReplyDelete