9 ms·
This will make the program instantly unportable, because not all Bourne shells are POSIX-compliant. Please don't do that. || exit 1 is portable.
by Annatar 7y ago
This will make the program instantly unportable, because not all Bourne shells are POSIX-compliant. Please don't do that. || exit 1 is portable.
- roryrjb 7y agoSo I guess I'm just used to POSIX compatible shells, it would be good to know about Bourne shells that aren't POSIX compatible (genuine question). But the shebang at the top of the script is bash so what I said is still correct in the context of the article. Stuff like multiple "|| exit 1"s makes people think that shell scripting is ugly and antiquated. I know that "#!/bin/sh" and "set -e" will work on all the BSDs, Solaris, Linux, macOS, what Unix is realistically left?
- ttsiodras 7y agoHi Rory. I am well aware of the flags you described - and indeed, they'd clean things up here. I am in fact tempted to go back and update the post - and either replace the shebang, or add the "early abort" flags. But TBH, keeping that script (that I wrote in 60 seconds) nice and clean was the least of my worries... Making the damn toolchain work had far, far higher priority :-) And after that, booting the LEON cores of course.
- roryrjb 7y agoYeah of course. I didn't mean to take anything away from the awesome work you are doing, this was nitpicking really, the script as it is, will work as intended, was really just highlighting this for the sake of others who may not be aware. Keep up the good work!
- Annatar 7y agoIt doesn't matter what people think, what matters is that the code is portable. Isn't it better that the program JustWork(SM) unmodified on all platforms without having to worry about whether the shell is POSIX-compliant? Up until the latest Solaris 10 patches, /bin/sh and /sbin/sh did not implement set -e, because on Solaris /bin/sh is the real McCoy - Steven Bourne's shell from 1972 - 1977. There is a fully POSIX compliant /usr/xpg4/bin/sh, but only Solaris experts know that the /usr/xpg4 directory exists and what is in it; 99.99% of the people out there won't have it before /bin or /usr/bin in their PATH. Portability should never be traded for convenience, because when one does that, one forces "the next guy" to waste his time fixing one's code. That's just wrong. I've had so much of my life wasted by GNU/Linux "bashisms" which were completely unnecessary. I resent that deeply. That's my life I could have spent in more productive and fulfilling ways, rather than fixing what should not have been broken to begin with. If you want to write portable shell programs, write them in ksh and then you won't have to worry about POSIX or non-POSIX.
- jamiek88 7y ago>Up until the latest Solaris 10 patches You speak in absolutes. Very dated absolutes as well. You might want to think about that. Solaris 10 release date: January 2005.
- mlyle 7y agoTurns out they're absolutely wrong absolutes, too, since Bourne's shell, as it shipped in V7, supported set -e.
- mlyle 7y ago> Up until the latest Solaris 10 patches, /bin/sh and /sbin/sh did not implement set -e, because on Solaris /bin/sh is the real McCoy - Steven Bourne's shell from 1972 - 1977. There's been a conformant POSIX shell on Solaris since 1995. /bin/sh has been conformant to this since 2007 or so. It is 2019. When should we be allowed to use it? POSIX is the standard for Unix portability and has been for the last 2 decades. System V never was. > Portability should never be traded for convenience, because when one does that, one forces "the next guy" to waste his time fixing one's code. That's just wrong. I've had so much of my life wasted by GNU/Linux "bashisms" "set -e" is not a bashism. The errflag was there from nearly the beginning. By the early 1979 BSD 3 development tree, it could be triggered by 'set -e'. When the POSIX standards committee decided to iron out differences between the BSD and SystemV branches of the Unix Family tree, they decided it was worth keeping, and over the next few years everyone conformed. > Portability should never be traded for convenience, because when one does that, one forces "the next guy" to waste his time fixing one's code. That's just wrong. I've had so much of my life wasted by GNU/Linux "bashisms" which were completely unnecessary. I resent that deeply. That's my life I could have spent in more productive and fulfilling ways, rather than fixing what should not have been broken to begin with. There's also things that are good for everyone else's productivity-- by e.g. not catering to someone who is stuck 18-40 years in the past.
- mlyle 7y ago> because on Solaris /bin/sh is the real McCoy - Steven Bourne's shell from 1972 - 1977 Wow-- I hadn't realized just how wrong your argument was! Bourne's shell from the outset supported set -e! From Bourne's "An Introduction to the Unix Shell", ~1977-1978 (converted to HTML at http://porkmail.org/era/unix/shell.html http://porkmail.org/era/unix/shell.html ) > The shell flag -e causes the shell to terminate if any error is detected. and the document goes on to state that you can use 'set' to set shell flags. It's in the V7 source, too: CHAR flagchar[] = { 'x', 'n', 'v', 't', 's', 'i', 'e', 'r', 'k', 'u', 0 }; INT flagval[] = { execpr, noexec, readpr, oneflg, stdflg, intflg, errflg, rshflg, keyflg, setflg, 0 }; Along with a proper call to options() in the set builtin. If the basis of your whole argument is history, you're complaining about something that would have worked on V7 or 3BSD. :D Apparently they are "too new." edit: Running V7 on a PDP-11 emulator has the anticipated results: boot Boot : hp(0,0)unix mem = 2020544 # RESTRICTED RIGHTS: USE, DUPLICATION, OR DISCLOSURE IS SUBJECT TO RESTRICTIONS STATED IN YOUR CONTRACT WITH WESTERN ELECTRIC COMPANY, INC. WED DEC 31 19:15:00 EST 1969 login: root Password: You have mail. # # # set -e # false login:
- McGlockenshire 7y agoWhich operating systems currently ship Bourne shells that aren't POSIX compliant? I know this was a thing 20-25 years ago, but is it still a problem now?
- mlyle 7y agoWhere are we going to come across a Bourne shell that doesn't like `set -e`? I accept that this choice might have been dubious 20 years ago, but we don't need to support SunOS 4.1.4 or SCO anymore... We're talking about standards that were published in 1992-1994 and that the overwhelming mass of the industry followed relatively quickly. To hold back 25 years later is nuts.
- sitkack 7y agoI see this crop up as "wisdom", for the sake of some quality, like that quality is an absolute. What the parent is literally advocating is that we don't ever fix the mistakes of the past. If you are generating a script that has to run everywhere, yes have the backend emit the verbose or tricky or unergonomic construct. But most of time, breaking portability to have something that is easier to understand, or more regular, that uses modern facilities is almost always the correct solution.
- mlyle 7y agoSo, I'm usually the curmudgeon that advocates for portability, slowness of change, etc. Only in the past couple years did I move from C99 to really employ C11/C18 features in most code. This, in particular, though, I think has been safe for a couple decades. What's "everywhere", anyways? We'll have a hard time even finding a system this won't work on. Especially in the context of FPGA tools that will only run on modern Linux, anyways...
- justinsaccount 7y ago> Especially in the context of FPGA tools that will only run on modern Linux, anyways... Right, annatar doesn't actually care that his "advice" here is completely wrong and irrelevant. His only goal is to derail any useful discussion in order to point out how smart he is and how terrible any software that isn't included with solaris 8 is.
- sitkack 7y ago