5 ms·
So 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 sheba
by roryrjb 7y ago
So 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: