Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How does one compare strings in zsh?

2,578 views
Skip to first unread message

Zubin Dittia

unread,
Apr 4, 1992, 5:53:34 AM4/4/92
to
I haven't used zsh before, and I've been having great difficulty
trying to get it to compare two strings. I read the man pages
several times, and this is what I came up with:
TESTSTRING="test string"
if ( [[ $TESTSTRING = "test string" ]] ) {
echo 'it works'
} else {
echo 'it does not work'
}
and unfortunately this does not work. I'd be grateful if some of
you shell gurus could help me out. Please e-mail your replies to
zu...@dworkin.wustl.edu
Thanks in advance.
-Zubin.

PS: I've been running zsh in an xterm, and several times it has died
with a segmentation fault. It also misbehaves sometimes when
displaying commands spanning more than one line from the history.
Does anyone know why this happens or how I can go about correcting
it?

Eric De Mund

unread,
Apr 4, 1992, 7:18:04 PM4/4/92
to
zu...@dworkin.wustl.edu (Zubin Dittia) writes:
>I haven't used zsh before, and I've been having great difficulty
>trying to get it to compare two strings. I read the man pages
>several times, and this is what I came up with:
> TESTSTRING="test string"
> if ( [[ $TESTSTRING = "test string" ]] ) {
> echo 'it works'
> } else {
> echo 'it does not work'
> }
>and unfortunately this does not work.

use [[...]] to test attributes of files and to compare strings. use
((...)) to test arithmetic expressions. example:

foo() {
if (( $# == 0 ))
then
echo usage: foo \<string\>
else
if [[ $1 = duck ]]
then
echo it\'s a duck
else
echo it\'s not a duck
fi
fi
}

% foo
usage: foo <string>
% foo cat
it's not a duck
% foo duck
it's a duck
%

see the ARITHMETIC EVALUATION and CONDITIONAL EXPRESSIONS section of
the zsh (v2.1.0) man page.

>PS: I've been running zsh in an xterm, and several times it has died
> with a segmentation fault. It also misbehaves sometimes when
> displaying commands spanning more than one line from the history.
> Does anyone know why this happens or how I can go about correcting
> it?

sorry, can't help you here. i don't experience this.

eric de mund
e...@netcom.com

Zubin Dittia

unread,
Apr 5, 1992, 7:51:34 AM4/5/92
to
In my original posting, I had claimed that the following sequence didn't
work for me:

TESTSTRING="test string"
if ( [[ $TESTSTRING = "test string" ]] ) {
echo 'it works'
} else {
echo 'it does not work'
}
I received a number of replies saying that this worked fine for others,
so I went back and recompiled zsh. Surprisingly, it worked fine that time.
The only difference between the two compiles was that I had used
"gcc -traditional" the first time, and "cc" the second. Apparently, zsh
misbehaves when compiled with gcc. Since I don't know the technical
differences between the two compilers (I normally prefer using gcc),
I can't speculate on the possible cause for this.

-Zubin.

Jonathan Hardwick

unread,
Apr 7, 1992, 8:51:28 AM4/7/92
to
zu...@dworkin.wustl.edu (Zubin Dittia) writes:
> The only difference between the two compiles was that I had used
> "gcc -traditional" the first time, and "cc" the second. Apparently, zsh
> misbehaves when compiled with gcc.

Counter-example: zsh runs fine on a DECstation 2100 when compiled with
V2.0 gcc -traditional -O2. It also gets a 10% size reduction over zsh
compiled with ultrix cc -O3. What machine and version of gcc are you
using?

Jonathan H.

ObShell : implementing Mach's setpath(1) as a single zsh function.

0 new messages