writing robust scripts.

David Collier from_busybox_maillist at dexdyne.com
Tue Nov 30 22:08:00 UTC 2010


I am trying to make all the scripts on my system run under set -e; set -u.

Firstly I'd like them to be as robust as possible when deployed, and
secondly if one fails in the field after 15 months, I want an entry in my
system log file to give me a clue what happened.

It's darned hard work because all sorts of scripts return values to
indicate their success.... and -e wants everything non-zero to mean
"error"

[ It would be really useful if one could say set -e 100 - so that values
over 100 could be used as pass-back tokens, reserving 0 and 1 for
conventional OK/error ]

also loads of scripts exploit the fact that an undefined variable is
equivalent to a blank.

I've set up a trap on exit, and all "expected" exits go through a do_exit
macro... so I can log any script that fails.

What would be truly useful would be a way to pick up the line number in
which an error is detected. The best I can do at the moment is "error in
script 'fred'"

Comments welcome, but my question is - does anyone else actually try to
do this stuff, or does everyone just busk it ?

D


More information about the busybox mailing list