2 ms·
>Let me tell you: shell is sort of a local optimum for one-off throwaway stuff, because it makes commonly needed thing accessible with so few keystrokes. But al
by coldtea 7y ago
>Let me tell you: shell is sort of a local optimum for one-off throwaway stuff, because it makes commonly needed thing accessible with so few keystrokes. But also, shell is a cute little hack. It's literally impossible to write robust programs in it.
But there's no essential reason why it has to be this way.
It's just that the first UNIX shell was a minimal and ad-hoc design, and the rest just accumulated BS craft in an unguided and even more ad-hoc way, without any vision or cohesion. Then POSIX came, and we got stuck with those (or hardly better versions, like zsh).
If by shell we define it as a programming language that has: first class support for job management, first class support for pipes, handy primitives for one-liners and file/text/job processing then there's absolutely no reason why such a language can't be much better than what we have.
For example, just off the top of my head:
- proper argument parsing (not just the BS hacks e.g. Bash allows)
- proper vectors and maps (not the primitive hacks bash allows - "shift" is so idiotic...)
- proper syntax (consider the BS [ vs [[ dichotomy in bash, or the millions of edge cases)
- proper exception/error handling (no just the primitive "traps" or checking $?)
- better expandability (e.g. consider the crappy kludge that autocomplete options are set)
- proper functions (not the arg1=$1 BS - shell could e.g. automatically assign to named arguments)
- namespacing
- packages, libraries. How many times people write and rewrite the same BS shell functions or primitives? "source" doesn't cut it.