Consider the following snippet being entered at the command line in bash:
$ echo $(( $(wc -l letter.txt | cut -c1-4)/66 + 1)) Supposing letter.txt exists and has 66*4 lines, then this puts the string 5 on the command line. Now what I cannot follow is how this conclusion follows based on what I know about command line processing.
My book (Sobell's A Practical Guide to Linux, 4e) says
The Bourne Again Shell scans each token for the various types of expansion and sub- stitution in the following order. Most of these processes expand a word into a single word. Only brace expansion, word splitting, and pathname expansion can change the number of words in a command (except for the expansion of the variable "$@"— see page 474).
- Brace expansion (next page)
- Tilde expansion (page 368)
- Parameter and variable expansion (page 368)
- Arithmetic expansion (page 369)
- Command substitution (page 371)
- Word splitting (page 372)
- Pathname expansion (page 372)
- Process substitution (page 374)
- Quote removal (page 374)
Based on the above, it would seem that the arithmetic expansion would evaluate first and, if so, the token $(wc -l letter.txt | cut -c1-4) is not a valid operand for the integer arithmetic which bash deals with. What is my way out here/what am I not understanding?
echo *in a directory containing a file called<(rm -rf ~/*)would delete the contents of your home directory. Luckily, that's not how it works. I can't imagine how they've figured that order would make any sense.