Date: Tue, 18 Feb 2003 11:14:48 -0500 From: Chet Ramey <chet@nike.ins.cwru.edu> To: phk@phk.freebsd.dk Cc: current@freebsd.org Subject: Re: Shell programming 101: Is this an expr(1) bug ? Message-ID: <030218161448.AA93484.SM@nike.ins.cwru.edu> In-Reply-To: <"Message from phk"@phk.freebsd.dk> References: <57374.1045568362@critter.freebsd.dk>
next in thread | previous in thread | raw e-mail | index | archive | help
> Running: > > #!/bin/sh > set -ex > > for p in ad2 ad0 ad1 > do > a0=`expr $p : '^ad\([0-9]\)$'` > done > > I get: > > syv# sh _ > + expr ad2 : ^ad\([0-9]\)$ > + a0=2 > + expr ad0 : ^ad\([0-9]\)$ > + a0=0 > syv# echo $? > 1 The `set -e' says to exit the shell if a simple command fails. POSIX.2 says that the exit status of an assignment statement without an accompanying command is either 0 or the exit status of the last command substitution performed while expanding the rhs. `expr' returns 1 when the result is `0'. Thus the assignment statement fails and the shell exits. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ( ``Discere est Dolere'' -- chet ) Chet Ramey, ITS, CWRU chet@po.CWRU.Edu http://cnswww.cns.cwru.edu/~chet/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?030218161448.AA93484.SM>