On 23 April 2017 at 03:59, Andrew McGlashan via luv-main <[email protected]> wrote: > > This problem was discovered when running run a bash script with "set > -ue" and having "((i++))" as the last command in a loop. > > The following script will quit with an error after the first iteration > due to the return code errantly being 1. > > #!/bin/bash > set -eu > i=0 > for a in a b c > do > echo "${a}" > ((i++)) > done
The "bug" you have discovered is expected behaviour for someone more experienced in this aspect of bash. On 23 April 2017 at 13:17, Andrew McGlashan via luv-main <[email protected]> wrote: > > Pre or post makes no real difference. But, doesn't the below script exhibit exactly the behaviour you wanted? set -eu i=0 for a in a b c do echo "${a}" ((++i)) done Also, the advice you have been given is good, dont use 'set -e' (for the reasons given in the other 2 replies, it causes trouble and is unecessary). It takes perseverance to master bash scripting because there are many unexpected non-obvious pitfalls and much of the information found by web searching encourages bad practice. Lurk on irc.freenode.net #bash for a while if you want to get better at it. _______________________________________________ luv-main mailing list [email protected] https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main
