[plug] bash scripting

James Devenish devenish at guild.uwa.edu.au
Tue Dec 23 19:56:42 WST 2003


In message <3FE82226.3010004 at wasp.net.au>
on Tue, Dec 23, 2003 at 03:08:22PM +0400, Brad Campbell wrote:
> Now this is all well and good, but bash takes any command
> that exits with an error code of [!=] 0 to mean an error.

(As it should.)

> I have kludged around it with such bodgery as
> 
> let count=0 || true

That is an epitome of the necessary style, as far as I know, though in
ksh and zsh, `true` is a built-in command and has negligible overhead.
However, in bash 2.05a, it appears there is no such built-in. This
suggests that /bin/true (or other executable from your PATH) will be
executed. For the specific case of `let count=0`, I would suggest that
an alternative is `integer count=0` (however, in Bash, I think you have
to use `typeset -i count=0` instead).

> as the shell does not look at the error code if it thinks it might be 
> part of a boolean expression.

Well, I would suggest that it *does* look at the exit status, but the
effect of the -e option depends not on the result of `let count=0`
but instead upon the exit status of `true`.





More information about the plug mailing list