Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 26 Jun 2005 12:00:25 +0300
From:      Vasil Dimov <vd@datamax.bg>
To:        hackers@freebsd.org
Subject:   Re: /bin/sh -e function parsing strangeness
Message-ID:  <20050626090025.GA77882@sinanica.bg.datamax>
In-Reply-To: <20050626082702.GA76984@sinanica.bg.datamax>
References:  <20050626082702.GA76984@sinanica.bg.datamax>

next in thread | previous in thread | raw e-mail | index | archive | help
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Sun, Jun 26, 2005 at 11:27:02AM +0300, Vasil Dimov wrote:
> 
> Can anyone explain this:
> 
> % sh -ec 'f() { return 5 ; } ; if f ; then echo tt ; else echo ff ; fi'
> ff
> % sh -ec 'f() { return 5 ; : ; } ; if f ; then echo tt ; else echo ff ; fi'
> % echo $?
> 5
> 
> If any commands appear after the return statement in a function,
> then -e flag triggers untested command failure although function call is
> tested with `if' statement.
> 

I see, -e counts for each command inside function body, no matter that
the whole function return status is tested with `if'.

% sh -ec 'f() { ls /nonexistent ; ls / ; } ; if f ; then echo tt ; else echo ff ; fi'
ls: /nonexistent: No such file or directory
%

Probably this should be considered as a sh "feature".

-----BEGIN PGP SIGNATURE-----

iD8DBQFCvm6pFw6SP/bBpCARAu6FAKCCoGXwounURHk6o4m8huqEDtmX9wCfXqxf
M0BT7Ej0fG9Iulgr/A18MMk=
=/5jF
-----END PGP SIGNATURE-----



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050626090025.GA77882>