by amelius · 8y ago · 0 comments
But, in my opinion, that's where it should stop: one shouldn't use a shell language for scripting. In scripts, it is simpler to use more verbose and clear constructs, because most editors are very powerful and provide shortcuts themselves.
>man bash
/\$\( # search pattern needs escaping
...
value is evaluated as an arithmetic expression even if the $((...)) expansion is not used (see Arithmetic Expansion below). Word split‐
...
n # go to next match
Command Substitution
Command substitution allows the output of a command to replace the command name. There are two forms:
$(command)
or
`command`
(detailed description follows)
I'm still in favor of using more verbose and especially more clear constructs, but not because they are easier for Google, but because they ideally hold enough information on their own that you don't even need to look it up to know what it does. type man foo
type /-p
type n n n n n n n n n
as there are a bunch of matches like “...does bar when combined with -p...”A presentation of man pages that used hypertext would make me a lot happier.
To use the original example, once you've identified that $(...) is Command Substitution, you have something that pulls up meaningful results in every search engine.
Amusingly, reference documents are themselves increasingly rare, and what you usually get is a rough tutorial and set of examples that cover perhaps 15% of the feature set, and need to dive into the source to figure everything else out.
Not having to put every command in quotes, for example, is a huge advantage all by itself, especially if any argument lists have quoted arguments.
The $(...) construct is pretty fundamental to bash scripting and should be covered in any decent tutorial.