[pacman-dev] bash scripts errexit and nounset options
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.
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
On Thu, Mar 12, 2009 at 12:06 AM, Allan McRae <allan@archlinux.org> wrote:
How does set -u work when you test if a variable exists? e.g. in makepkg we test if "$install" is non-null.
It can be defined and null. That just means we have to declare all variables we use. So this change would certainly require additional declarations. I guess more safety comes at a price :)
Xavier wrote:
On Thu, Mar 12, 2009 at 12:06 AM, Allan McRae <allan@archlinux.org> wrote:
How does set -u work when you test if a variable exists? e.g. in makepkg we test if "$install" is non-null.
It can be defined and null. That just means we have to declare all variables we use. So this change would certainly require additional declarations. I guess more safety comes at a price :)
The more I look into including these flags, the more I like the idea. If you are not going to look into this in the near future, could you file a bug report so it is not forgotten? Cheers, Allan
On Wed, Mar 11, 2009 at 6:26 PM, Allan McRae <allan@archlinux.org> wrote:
Xavier wrote:
On Thu, Mar 12, 2009 at 12:06 AM, Allan McRae <allan@archlinux.org> wrote:
How does set -u work when you test if a variable exists? e.g. in makepkg we test if "$install" is non-null.
It can be defined and null. That just means we have to declare all variables we use. So this change would certainly require additional declarations. I guess more safety comes at a price :)
The more I look into including these flags, the more I like the idea. If you are not going to look into this in the near future, could you file a bug report so it is not forgotten?
Poke to one of you two? Or did a report get filed? -Dan
On Sat, Apr 11, 2009 at 9:46 PM, Dan McGee <dpmcgee@gmail.com> wrote:
Poke to one of you two? Or did a report get filed?
Dan McGee wrote:
On Wed, Mar 11, 2009 at 6:26 PM, Allan McRae <allan@archlinux.org> wrote:
Xavier wrote:
On Thu, Mar 12, 2009 at 12:06 AM, Allan McRae <allan@archlinux.org> wrote:
How does set -u work when you test if a variable exists? e.g. in makepkg we test if "$install" is non-null.
It can be defined and null. That just means we have to declare all variables we use. So this change would certainly require additional declarations. I guess more safety comes at a price :)
The more I look into including these flags, the more I like the idea. If you are not going to look into this in the near future, could you file a bug report so it is not forgotten?
Poke to one of you two? Or did a report get filed?
Sure... http://bugs.archlinux.org/task/13767 . You are one of the assignness! Allan
participants (3)
-
Allan McRae
-
Dan McGee
-
Xavier