6 ms·
??? This complaint seems more than 20 years too late Arithmetic is built into POSIX shell, and it's universally implemented. The following works in basically
by chubot 2y ago
??? This complaint seems more than 20 years too late
Arithmetic is built into POSIX shell, and it's universally implemented. The following works in basically every shell, and starts 0 new processes, not 2:
$ bash -c '[ $((1 + 1)) = 2 ]; echo $?'
0
$ zsh -c '[ $((1 + 1)) = 2 ]; echo $?'
0
$ busybox ash -c '[ $((1 + 1)) = 2 ]; echo $?'
0
YSH (part of https://oils.pub/ https://oils.pub/ ) has a more familiar C- or JavaScript-like syntax:
$ ysh -c 'if (1 + 1 === 2) { echo hi }'
hi
It also has structured data types like Python or JS:
$ echo '{"foo": 42}' > test.json
$ ysh
ysh-0.28$ json read < test.json
ysh-0.28$ echo "next = $[_reply.foo + 1]"
next = 43
and floats, etc.
$ echo "q = $[_reply.foo / 5]"
q = 8.4
https://oils.pub/release/latest/doc/ysh-tour.html https://oils.pub/release/latest/doc/ysh-tour.html (It's probably more useful for scripting now, but it's also an interactive shell)
- DonHopkins 2y ago20 years doesn't even get you back to the last century, it's more like 48 years since 1977 when Bourne wrote sh. As one of the authors of the Unix Haters Handbook, published relatively recently in 1994, and someone who's used many versions of Unix since the 1980's, of course I'm fully aware that those problems are hell of a lot more than 20 years old, and that's the whole point: we're still suffering from their "vestigial historic baggage", arcane syntax and semantics originally intended to fork processes and pipe text to solve trivial tasks instead of using shared libraries and machine instructions to perform simple math operations, and people are still trying to justify all that claptrap as the "Unix Philosophy". Care to explain to me how all the problems of X-Windows have been solved so it's no longer valid to criticize the fallout from its legacy vestigial historic baggage we still suffer from even today? How many decades ago did they first promise the Year of the Linux Desktop? The X-Windows Disaster: This is Chapter 7 of the UNIX-HATERS Handbook. The X-Windows Disaster chapter was written by Don Hopkins. https://medium.com/@donhopkins/the-x-windows-disaster-128d398ebd47 https://medium.com/@donhopkins/the-x-windows-disaster-128d39... Why it took THREE processes and a shitload of context switches and punctuation that we are still stuck with to simply test if 1 + 1 = 2 in classic Unix [TM]: [ "$(expr 1 + 1)" -eq 2 ] Breakdown: expr 1 + 1 An external program used to perform arithmetic. $(...) (Command substitution) Runs expr in a subshell to capture its output. [ ... ] In early shells, [ (aka test) was also an external binary. It took THREE separate processes because: Unix lacked built-in arithmetic. The shell couldn't do math. Even conditionals ([) were external. Everything was glued together with fragile text and subprocesses. All of this just to evaluate a single arithmetic expression by ping-ponging in and out of user and kernel space so many times -- despite the CPU being able to do it in a single cycle. That’s exactly the kind of historical inefficiency the "Unix Philosophy" retroactively romanticizes.
- chubot 2y agoI'm aware it used to be that way, but it's long been fixed It's fine to hate Unix, but you should update your examples :)
- DonHopkins 2y agoI'll update my examples when your examples of how it's been fixed don't use the same arcane syntax and semantics as the 48 year old Bourne shell. That's the whole point, which you're still missing. > $ bash -c '[ $((1 + 1)) = 2 ]; echo $?' Not even Perl uses that much arcane punctuation to test if 1 + 1 = 2. As if [] isn't enough, you've got to throw in two more levels of (()), plus enough grawlix profanity for a Popeye comic strip. And people complain Lisp has too many parens. Sheez. https://en.wikipedia.org/wiki/Grawlix https://en.wikipedia.org/wiki/Grawlix There's even an emoji for Unix shell syntax: https://www.compart.com/en/unicode/U+1F92C https://www.compart.com/en/unicode/U+1F92C
- Datagenerator 2y agoWhat are good shells in your opinion?
- anthk 2y agorc and 9front's philosophy. Unix, but better and removing all the cruft.
- DonHopkins 2y agoI prefer ITS DDT (aka HACTRN), with its built-in PDP-10 assembler and disassembler, that lets you do things like your login file customizing your prompt in assembly code to print the time by making system calls, without actually spawning any sub-jobs to merely print the time: https://gunkies.org/wiki/ITS_DDT_Guide https://gunkies.org/wiki/ITS_DDT_Guide ..PROMPT holds the instruction which DDT uses to type out a "*". You can replace it with any other instruction. To use "%" instead of "*", deposit $1#%$> in that location ($> to avoid clobbering the opcode without having to know what it is) If you have to use arcane syntax and grawlix profanity, you should at least have direct efficient access to the full power of the CPU and operating system. https://en.wikipedia.org/wiki/Incompatible_Timesharing_System https://en.wikipedia.org/wiki/Incompatible_Timesharing_Syste... https://en.wikipedia.org/wiki/Dynamic_debugging_technique https://en.wikipedia.org/wiki/Dynamic_debugging_technique https://web.archive.org/web/20061011004003/http://www.sigfs.org/its-reference/its-reference-1.5.html#tth_chAp7 https://web.archive.org/web/20061011004003/http://www.sigfs.... https://its.victor.se/wiki/luser https://its.victor.se/wiki/luser https://www.hactrn.net/sra/alice/alices.pdp10 https://www.hactrn.net/sra/alice/alices.pdp10 https://gunkies.org/wiki/Incompatible_Timesharing_System https://gunkies.org/wiki/Incompatible_Timesharing_System (I recognize that photo I took of MIT-MC at the MIT-AI Lab!) https://gunkies.org/wiki/File:Mit-mc.jpg https://gunkies.org/wiki/File:Mit-mc.jpg Even the Apple ][ Integer Basic monitor ROMs had a build-in mini assembler and disassembler. https://www.ldx.ca/notes/apple2-notes.html https://www.ldx.ca/notes/apple2-notes.html