[pacman-dev] bash scripts errexit and nounset options

Allan McRae allan at archlinux.org
Wed Mar 11 19:06:12 EDT 2009


Xavier wrote:
> I found this page while implementing the locking system for repo-add,
> I stole some code from it :
> http://www.davidpashley.com/articles/writing-robust-shell-scripts.html
>
> It recommends using set -u and set -e, these both seem like a good idea to me.
> Should we try to be consistent using these options in all the bash
> scripts in pacman repo?
> Several already use set -e, but not all of them. And none seem to use set -u.
>
> While I find these two options useful, I wonder if it isn't a bad idea
> to introduce them now, as it could cause more harm than good.
> I guess that ideally, they would have been set from the beginning.
> Adding them now could add some non obvious problems to code that
> worked fine.
>
> Anyway, if we agree these flags are indeed useful, they could at least
> be considered when adding new scripts.

How does set -u work when you test if a variable exists?  e.g. in 
makepkg we test if "$install" is non-null.

Anyway, I think these are good to have as they help us discover errors 
in our assumptions.  I would be up for adding them to all scripts once 
we get the next release out the door.

Allan




More information about the pacman-dev mailing list