4 ms·
> It also turns out that getting a shell correct is a lot more experimentation and a lot less following what the textbooks say. In practice, things like ‘stdout
by ChrisSD 6y ago
> It also turns out that getting a shell correct is a lot more experimentation and a lot less following what the textbooks say. In practice, things like ‘stdout’ and ‘stderr’ are used in a variety of ways, as are the exit codes output by programs. Our initial designs started with a stricter view of these ideas, and softened over time as we saw that the real world is a much fuzzier place than we realized.
Good point. Exit codes can be difficult. A non-zero error value may not be an error; it could indicate a type of success or be a warning or a result of a calculation or any number of things depending on the application.
- wwright 6y agoAt work we have a program that uses the exit code to encode three enums. Each digit of the decimal representation of the exit code corresponds to one of these enums. It’s some of the most cursed code I’ve ever worked with. (God bless anyone who ever used this program and got a set fault or sigint or sighup and therefore a bizarre result.)
- etaioinshrdlu 6y agoThat is a very bad design. Especially since you have only one byte to work with. What is the decimal range of values used?
- wwright 6y agoI think 11 to 200, but it’s not surjective
- samatman 6y agoI was horrified by your post, because I've had to deal with load-bearing exit codes. Then, I read the part about each digit of the decimal representation. Now I may need to lie down for a spell.
- adamch 6y agoIn a redesigned shell, ideally there would be a richer way to describe the result of a program. Maybe "return an integer and consult the manual to see what it means" isn't the best way forward. Personally, I think Result types from Rust/Haskell/Swift make a lot of sense -- a program either succeeds with some output, or fails with an explanation of why. By default, pipes stop piping if one command fails.
- moonchild 6y ago> Personally, I think Result types make a lot of sense -- a program either succeeds with some output, or fails with an explanation of why Usually, this is what happens. Usually, the error-signalling return is accompanied by a message (posted to stderr). > By default, pipes stop piping if one command fails set -o pipefail
- toastal 6y agopipefail is not available to POSIX shells like dash
- roryrjb 6y agoset -o pipefail is now part of POSIX[0] and I believe as soon as someone posts a patch to dash to implement it, it will get included[1]. [0]. https://www.austingroupbugs.net/view.php?id=789 https://www.austingroupbugs.net/view.php?id=789 [1]. https://lore.kernel.org/linux-dash/20200701015226.GA6839@gondor.apana.org.au/T/#t https://lore.kernel.org/linux-dash/20200701015226.GA6839@gon...
- toastal 6y agoThis is great! Thanks for posting it.
- karl42 6y agoPlan9 returns an error string instead of an error integer with the empty string signifying success. This seems like a simple and useful improvement to me.