> 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    [EMAIL PROTECTED]    http://cnswww.cns.cwru.edu/~chet/

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to