-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 14/02/15 16:53, Les Mikesell wrote: <snip>> To understand it completely you need to know the order of > operations as the shell makes multiple passes over the line, > parsing, processing metacharacters, and expanding variables. And > I don't know where to find a concise description of that any more.man bash, about 900 lines down under "EXPANSION". -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAEBAgAGBQJU34eBAAoJEAF3yXsqtyBlNuYP/iPLOPY/SbXeGgpZOnJKZ3qH U7cnh56unXT3pTwQ8podSDNbLtiSOt8R729JFpNMwNb4Bzf9XFGaDyCn11DIdOuU RpuZ72NFxC8ezPcWlzvlYZuNRDIso4iQbHt5BjEutJ7RfSOdl+FoUdtXpXYATtaB YB4UQMShFVAr2AeNbJd/IuOopYSplZwd2qJXpAq0cZwtTWjbTkQG4zJOWIAip1kM 0q+5u3BKrP6ZEY7fWDhdCcJFZRRv+zAQaEnz42WUmEOROziF9sWzSxLOug87diA0 WcdEIoiNTuprFIeuICJvzTL1AhhjcYgm8+zBUb+xKpbBpJePQOtJ7Wd3RbkgEFhe 66hSNbLvYovqHgmz9E4H12ZnYW4JTmV8UE842JoliWqfNaD6v9wwaDmISekqm9jS 3f7Oc4fC7O+xao77T2jIHW4syMmG5Fdt8enyTR4QkRnx6W6sSTR6JKjii9GGo6P0 j5mA31KDQQyrJU6WqjL2TFgdZTF2zuL65xtEzxcWumpkqi6TaJodSnkIRH+ldgdg medZ910pxmJphojST0dsefJeptJfTw8qq16siatqj5r3+c6mUjTRRHkVVTyrlYHf 2h0t3ax+pQq0Fa9zx7Y0wIS+Qg8ihFC4XLJOQ+RI1WkG2jPCsaUHtkCYQxiZ/VK9 HOoe2d0MAGmNc4Yy2ex/ =UeON -----END PGP SIGNATURE-----
On Sat, Feb 14, 2015 at 11:36 AM, J Martin Rushton <martinrushton56 at btinternet.com> wrote:> <snip> >> To understand it completely you need to know the order of >> operations as the shell makes multiple passes over the line, >> parsing, processing metacharacters, and expanding variables. And >> I don't know where to find a concise description of that any more. > > man bash, about 900 lines down under "EXPANSION".But it is not 'just' expansions. You need to know the full order of operations with all the steps - word splitting, quote removal, i/o redirection, groupings, etc., some of which is repeated over the line after some of the other steps happen. I think I saw this in an understandable form for the bourne shell back in the 1980's but can't remember it well enough to describe and all the bash docs I've seen are way too convoluted to just see the order of operations as a simple set of steps - that you need to know before any of the rest will make sense. -- Les Mikesell lesmikesell at gmail.com
On 02/14/2015 12:03 PM, Les Mikesell wrote:> On Sat, Feb 14, 2015 at 11:36 AM, J Martin Rushton > <martinrushton56 at btinternet.com> wrote: >> <snip> >>> To understand it completely you need to know the order of >>> operations as the shell makes multiple passes over the line, >>> parsing, processing metacharacters, and expanding variables. And >>> I don't know where to find a concise description of that any more. >> >> man bash, about 900 lines down under "EXPANSION". > > But it is not 'just' expansions. You need to know the full order of > operations with all the steps - word splitting, quote removal, i/o > redirection, groupings, etc., some of which is repeated over the line > after some of the other steps happen. I think I saw this in an > understandable form for the bourne shell back in the 1980's but can't > remember it well enough to describe and all the bash docs I've seen > are way too convoluted to just see the order of operations as a simple > set of steps - that you need to know before any of the rest will make > sense.It's the 4 paragraphs at the start of the "EXPANSION" section: Expansion is performed on the command line after it has been split into words. There are seven kinds of expansion performed: brace expansion, tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, word splitting, and pathname expansion. The order of expansions is: brace expansion, tilde expansion, parameter, variable and arithmetic expansion and command substitution (done in a left-to-right fashion), word splitting, and pathname expansion. On systems that can support it, there is an additional expansion avail- able: process substitution. Only brace expansion, word splitting, and pathname expansion can change the number of words of the expansion; other expansions expand a single word to a single word. The only exceptions to this are the expansions of "$@" and "${name[@]}" as explained above (see PARAMETERS). -- Bob Nichols "NOSPAM" is really part of my email address. Do NOT delete it.