Subject: Re: correct shell behaviour?
To: <>
From: David Laight <david@l8s.co.uk>
List: tech-userlevel
Date: 08/12/2002 10:31:27
> A quick test shows that ksh93's "0" is the status of the "echo a".
> $ echo `cmp -s /etc/group /etc/group; exit 3` >`echo /dev/tty; exit 2` $?
> 0
> $ echo `cmp -s /etc/passwd /etc/group; exit 3` >`echo /dev/tty; exit 2` $?
> 1
> $ echo `if cmp -s /etc/passwd /etc/grope; then exit 3; else exit 4; fi` $?
> 2
> These results are... counterintuitive.
Erm badly broken? It looks as though 'exit n' isn't setting the result!
>
> > x=$(echo var >&2) : >/dev/null$(echo redir >&2) $(echo arg >&2)
>
> All but V7 sh agree:
> arg
> var
> redir
The posix spec says arg, redir, var for normal commands but allows
arg, var, redir for 'special builtins' (which include : but not echo).
>
> Apparently not... but for
>
> $ (exit 2)
> $ a=a
> $ echo $?
>
> all do produce
> 0
That is the behaviour that posix requests.
David
--
David Laight: david@l8s.co.uk