Re: feature request: more complete set -e

2009-06-30 Thread Chet Ramey
Marc Weber wrote: > Chet: >> To do otherwise would have made expr much less useful. Idioms such as >> >> var=10 >> while var=`expr $var - 1` >> do >> echo $var >> done > > Mmh I'd use the C like for loop for this which is supported by bash as well. > A relatively recent addition to the

Re: feature request: more complete set -e

2009-06-30 Thread Greg Wooledge
On Tue, Jun 30, 2009 at 09:58:45PM +0200, Marc Weber wrote: > How is this done? > > CHK0="test $? == 0" > my_important_task; $CHK0 || exit 1 You'd need single quotes instead of double there. (And == is illegal in Bourne/POSIX shell test commands; only bash tolerates it.) You could also use a fu

Re: feature request: more complete set -e

2009-06-30 Thread Marc Weber
Greg Wooledge: > If you simply handle errors yourself by checking the return > code from commands that actually matter, you won't have to worry about > all these nasty little surprises. How is this done? CHK0="test $? == 0" my_important_task; $CHK0 || exit 1 Chet: > To do otherwise would have m

Re: feature request: more complete set -e

2009-06-29 Thread Bob Proulx
Chet Ramey wrote: > It depends on what you mean by `fail'. > ... > To do otherwise would have made expr much less useful. Idioms such as Also I must mention grep too. The exit status of grep isn't just whether it exits without an error but instead returns an indication of whether the pattern mat

Re: feature request: more complete set -e

2009-06-29 Thread Chet Ramey
> > echo `expr $var - 1` > shrug. I didn't knew that either. > I think that this is bad. expr should do some calculation. If the > calculation fails (eg devision by zero) the return value should be non > zero. It depends on what you mean by `fail'. expr certainly returns a non-zero result for th

Re: feature request: more complete set -e

2009-06-29 Thread Greg Wooledge
On Mon, Jun 29, 2009 at 12:45:29AM +0200, Marc Weber wrote: > > echo `expr $var - 1` > I think that this is bad. expr should do some calculation. If the > calculation fails (eg devision by zero) the return value should be non > zero. You'd think so, but alas, the people who made expr(1) had a diff

Re: feature request: more complete set -e

2009-06-28 Thread Marc Weber
On Thu, Jun 25, 2009 at 07:33:18PM -0400, Chet Ramey wrote: > Marc Weber wrote: > > > This is my point: I'd like to tell bash: Whenever running an executable > > assume that if it returns a non zero exit status that's a unforeseen > > exception. And in this case don't continue as usual but abort a

Re: feature request: more complete set -e

2009-06-25 Thread Chet Ramey
Marc Weber wrote: > This is my point: I'd like to tell bash: Whenever running an executable > assume that if it returns a non zero exit status that's a unforeseen > exception. And in this case don't continue as usual but abort and return > non zero exit status yourself. set -e comes close. You're

Re: feature request: more complete set -e

2009-06-24 Thread Marc Weber
On Tue, Jun 23, 2009 at 09:00:10AM -0400, Chet Ramey wrote: > Marc Weber wrote: > > Hi, > > > > I stumbled about another bash problem today: > > > > for item in $(false); > > echo $item > > done || { echo for failed; } > > > > doesn't fail. I think it's bad that there is no > > set -e > >

Re: feature request: more complete set -e

2009-06-23 Thread Chet Ramey
Marc Weber wrote: > Hi, > > I stumbled about another bash problem today: > > for item in $(false); > echo $item > done || { echo for failed; } > > doesn't fail. I think it's bad that there is no > set -e > > like switch which really catches all failures of this kind. This isn't really abo