FS#13767 - Use errexit and nounset options in all bash scripts from pacman source tree
Attached to Project:
Pacman
Opened by Xavier (shining) - Thursday, 12 March 2009, 10:35 GMT
Last edited by Allan McRae (Allan) - Friday, 09 March 2012, 05:41 GMT
Opened by Xavier (shining) - Thursday, 12 March 2009, 10:35 GMT
Last edited by Allan McRae (Allan) - Friday, 09 March 2012, 05:41 GMT
|
Details
The following page recommends using set -u and set -e, which
both seem like a good idea to me :
http://www.davidpashley.com/articles/writing-robust-shell-scripts.html 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. This setting will very likely require several changes (declaring all variables we use, even when we just check for emptiness). But I am not sure if it is worth the trouble adding these to the existing mature scripts. It might require a hell lot of testing, maybe even several releases before the scripts are used in all sort of corner cases and all problems are found. In this case, it could still be worth adding them to the most basic scripts, and/or to the new ones that are added. |
This task depends upon
Closed by Allan McRae (Allan)
Friday, 09 March 2012, 05:41 GMT
Reason for closing: Won't implement
Additional comments about closing: See final comment
Friday, 09 March 2012, 05:41 GMT
Reason for closing: Won't implement
Additional comments about closing: See final comment
I agree that maybe it isn't a good idea to put it in there without lots of testing. At first I set it when I was making changes and when I was sure my new code was good I unset it. But now I leave it set everywhere anyway.
FS#15645).As a reminder for later.... ${foo:-""} prevents nounset erroring during the [ -z "$foo" ] style tests.
Even for the simple and recent rankmirrors bash script, it was written with the default bash behavior in mind, and well tested. I thought about adding errexit and nounset but I gave up, it really looked counter-productive.
I still think these options are good, but only if you start from scratch with them in mind.
So I would just close my bug report. It was just a FYI :)
http://archlinux.me/brain0/2009/08/16/shit-happens-when-you-party-naked-or-use-crappy-shell-scripts/
So this is going to be "Won"t Implement"