Repository navigation
Sync logical operators in shell scripting code - #13560
Conversation
This updates the obsolescent `-a` and `-o` binary primaries to `&&` and `||`. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
|
Didn't test it, but doesn't this spawn multiple processes per condition? What was wrong with -a and -o? Seems like a case of "don't fix it if it's not broken" |
|
@thg2k, these usages are obsolete. Not broken and will most likely work everywhere in current shells, yet just written with low quality. See POSIX notes above. This syncs it with the rest of the usages across other files. And so we have less confusions like these: #13396 (comment) which style to use. And Autoconf docs suggestion also looks good to me: https://www.gnu.org/software/autoconf/manual/autoconf-2.72/autoconf.html#Limitations-of-Shell-Builtins There are probably gazillion other issues in these shell scripts and code, so we'll see which to address and which to leave out. Like these "x$var" comparisons and similar. For now, that's good. Multiple processes per condition? I'm not sure that's the case here. No? |
|
Thank you for the pointers @petk, I've read it up and indeed it says they are obsolete. I find it hard to believe as I grew up writing my shell scripts with "-a" and "-o", but what can you do, progress is progress. About the spawning multiple shells, I checked with strace and it does not. What I mean is that All in all, I will still continue writing my scripts with -a and -o, but thanks to you now I know I officially write obsolete code 😆 |
|
@thg2k I'm glad to hear that. Yes, you can safely use these doubled, tripled, etc. test calls inside the if. Yes, that && operator in those commands is a bit of a different thing. But I'm also not sure whether it would spawn two processes. 🤔 However, the |
This updates the obsolescent
-aand-obinary primaries to&&and||.https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html