Hacker News new | ask | show | jobs
by jblow 2352 days ago
Obviously, but then the answer is, why? What the hell is our problem?

Even if you think shell scripting is a good idea (which I don’t), just fix all the obviously dumb toxic stuff like this and put out a shell that is minimally different with only semantic fixes. Emit warnings now for toxic semantics but still support them, and in a couple of years, turn off that support for good.

4 comments

Part of the problem is people reading the title of Richard P. Gabriel's "Worse is Better" without actually reading the paper, and adopting Worse as a design goal.

https://en.wikipedia.org/wiki/Worse_is_better

I think the problem is the people who don't understand the difference between "obviously dumb toxic stuff" and "features".

This thread is all about the difference between $* and $@. The difference is explained in the man pages for most shells, but since most programmers don't read instructions, they often need blog posts to explain to them how a documented feature of a language works.

I highly recommend the dash man page (http://man7.org/linux/man-pages/man1/dash.1.html) as a concise explanation of portable shell syntax. From the dash man page, under Special Parameters:

     *            Expands to the positional parameters, starting from one.
                  When the expansion occurs within a double-quoted string it
                  expands to a single field with the value of each parameter
                  separated by the first character of the IFS variable, or
                  by a ⟨space⟩ if IFS is unset.

     @            Expands to the positional parameters, starting from one.
                  When the expansion occurs within double-quotes, each posi‐
                  tional parameter expands as a separate argument.  If there
                  are no positional parameters, the expansion of @ generates
                  zero arguments, even when @ is double-quoted.  What this
                  basically means, for example, is if $1 is “abc” and $2 is
                  “def ghi”, then "$@" expands to the two arguments:

                        "abc" "def ghi"
It turns out we didn't need a blog post to explain it, because it's in the manual that nobody reads. But we should definitely complain about how this crafty, unusual piece of obviously dumb toxic stuff works, because how were you supposed to know to RTFM?

To answer your question "why still in 2020?", it's because these are independent features people needed. Sometimes people wanted the $* semantics, and sometimes the $@ semantics. So both exist. It's up to you to learn how the system works and use it properly.

It's not like Python doesn't also have weird edge cases that you won't know until you learn the whole language. I've seen people spend hours futzing about with lambdas and list comprehensions to try to fix a bug, which I addressed by just rewriting the expressions as regular-old loops and data structures. Bash isn't uniquely bad, it has warts like everything else. Take out the warts you don't want and someone else will complain that they're missing.

Yes, it takes a lot of experience and mindfulness to develop the taste for what is genuinely healthy and what ultimately is bad, even if it tastes good.
> in a couple of years, turn off that support for good.

Make that at least 50 years, if not 100. You have no control over every place where shell scripts are run.

Just do it.
I feel like "busy working on a different programming language" is one of the better excuses for not doing this.