This is a great name for a concept that I’ve found to be true. I’ve referred it a lot over the years.
I’m working on shell autocompletion now, and I’m surprised by how many bugs there are in bash and the separate bash-completion project that I’ve never noticed.
For example, try:
$ echo $(dirname <TAB>
$ echo `dirname <TAB>
in bash on your distro, or with bash --norc (which disables customization).
For me, I now notice 3 or 4 separate problems trying to complete simple command substitutions!
I think I must have been trained long ago not to attempt this. I just type out the whole command rather than try to tab complete it when there’s a substitution (which is not that often, but also not rare).
What is the issue with echo $(dirname <TAB>? I just now tried it and … it acted as expected.
echo $(dirname <TAB>
I get the issue that @whbboyd posted below. On second thought, I thought this was due to my customizations. On third thought, maybe not, because someone else got it.
However, I asked my friend to try the same thing on Ubuntu – he got the opposite behavior. $() worked but backticks caused a parse error on stderr!!
I’ve been wading through bash-completion code, and the bottom line is that it’s super hacky and it’s not at all surprising that there are bugs.
Fundamentally, it is a bash parser in bash !!! For real. Because bash makes a lame attempt at tokenizing your command line with COMP_WORDBREAKS, not even using its parser, and then bash-completion has to paper over it using string manipulation in bash. (The file is /usr/share/bash-completion/bash_completion on Debian / Ubuntu.)
Basically I’m not surprised if it behaves differently for different people, judging by the code. I might do a survey of this later to get a rough sense of numbers.
In Bash? I get
$ bash --version
GNU bash, version 4.4.12(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ echo $(dirname bash: unexpected EOF while looking for matching `)'
bash: syntax error: unexpected end of file
You probably do need bash_completion enabled to trigger this bug; I didn’t check without it.
Thanks, this is what I got too! But oddly enough a friend hit a different bug on Ubuntu (which I also use). I might do a survey of this.
There is a talk about Foundation DB that outlines these exact concepts. It’s amazing how many people stumble on this idea. After seeing the Foundation DB talk I wrote about it as well: https://www.scriptcrafty.com/2014/12/the-ecology-of-people-culture-and-tools/. I like Regehr’s take on it though.
This is why there is no excuse or substitute for not putting our creations in front of the end-user as quickly as possible.
It’s also why every project should try and understand–if you’re figuring out how much you can get away with bugs while meeting deadlines–if you’re targeting power users or normal users. If the users are going to be forced to deal with complexity, or if they’re going to be forced to use the software but can be told how to work around bugs, then that opens up some room for compromises that doesn’t exist otherwise.