3 ms·
While we're wishing in one hand, how is it that our programs still take an input of an array of strings, that get escaped and unescaped and split randomly by ou
by saalweachter 4y ago
While we're wishing in one hand, how is it that our programs still take an input of an array of strings, that get escaped and unescaped and split randomly by our shell scripts?
- ilyt 4y agoThat is entirely due to sh/bash and friends being a terrible programming language. All sensible ones allow you to just pass an array of parameters to command execution and not worry about spaces in them
- Spivak 4y agoThe irony is that I’ve had to add shell word splitting into in my real programming language code because of how many people prefer run(f”command {arg} -v -p{opt} {target}”) to run([“command”, arg, “-v”, “-p”, opt, target])
- saalweachter 4y agoThat's only, like, half the problem. It's an array of string parameters. No semantics! Just an variety of customs about what it means when a parameters begins with a - or a -- or if you have -- by itself preceding some characters, how to break lists of arguments with separators, what happens when you pass the same argument twice, etc etc etc. To choose the worst possible solution better than that, we could instead be passing in a single string with a JSON dictionary that says things like '{ "recursive": True, "force": True, "files": [ "file1", "file2", "file3" ]}'
- NathanOsullivan 4y agoFWIW bash supports arrays, and running commands with an array providing the arguments