|
wc is not a builtin. In that example we're not in front of a bash word splitting issue. I agree with you that shell scripting has caveats one need to learn. As does Perl, C, PHP, Ruby, Node, Go, Java and what not. I don't feel a big change is needed to handle spaces in shell scripts, my scripts handle them and I enjoy writing them. Maybe you know of minor tweaks for bash,zsh or any common shell which could be useful in general purpose of files with spaces in the name? don't hesitate to open them a bug, maybe we even get a fix. But don't send them this example, and insist on it, because the conversation is over: $ touch a_file
$ ls | wc
1 1 7
$ rm a_file
$ touch "a file"
$ ls | wc
1 2 7
Equivalent input, with/without spaces and expected output.The 2 is a word count, and we did pass two words, I don't expect a 1 there, _that_ could be a bug. |
If you want a difficult example, then take a more real-world example: e.g. the workflow of a 'find [some stuff] |grep [some other stuff]' is one to consider. That's where horrid workarounds like -print0 and -z have to come in, but the simple 'find|grep' works fine up until a file has a space in it.
As I said, there's no simple fix, even for the re-organised form of 'grep [some other stuff] `find [some stuff]` because the shell can't tell the difference between a filename and just a stream of text in the output of one program.