Hacker News new | ask | show | jobs
by xlii 1276 days ago
It’s easy to reason. It’s a shell that takes commands first and not designed programming language.

I have no idea what 1st would evaluate (guess is that PICK is empty and can is run with you as an arg with PICK as execution context)

Second - simple. Run the with THE=tell as execution context.

Third - set variable to string containing space using backslash as escape

Fourth - set variable to string with interpolation (but also useful when it contains quotes)

Fifth - set variable to string sans interpolation (but also could be used to wrap strings with double quotes)

There are (at least) 2 rationales for that. First - shell have execution context. You need to be able to set it on command so syntax has to allow this. Dedicated programming languages ignore that because everything is some form of a block.

The other thing is actually quite fun. Shell existed before we used displays, so you could have printer connected to input. Imagine creating variable and then getting to “oh boy I need to add white space char” without possibility to do backspace. Escaping was more viable solution.

On top of that there are many shells with different APIs. Scripting languages were made so one could work with shell while having stable API and sensible construct units. Sure they either moved forward (like Python) or slipped into oblivion (like Perl), so it’s back for shell scripting for some.

But after doing some stuff with AppleScript lately I think it could be worse.