On Sun, Aug 31, 2025 at 14:13:17 +0200, [email protected] wrote: > Aug 30, 2025, 12:08 by [email protected]: > > > All of these are compound commands, and must be parsed as a whole before > > executing any of the simple commands contained inside them. > > > > Sorry, Greg, but this is no "compound" command, these are separate commands: > > $ shopt -s extglob; echo !(this)
That is another case where it fails, correct. However, in your original email, you did indeed have the shopt inside a compound command. That's why I phrased it the way I did. If you wish, I'll add some additional verbosity to my original warning: Turning on extglob changes how bash parses its input, and bash parses line by line. In addition, bash has to parse compound commands (if, for, while, functions and so on) as a whole. The "shopt -s extglob" command must have been parsed and executed BEFORE the parser tries to use extended globs. Therefore, you cannot put "shopt -s extglob" on the same line, or in the same compound command, as any extended glob. I always advise people that if they're going to use extglob, it should be done right up at the top of the script, either immediately below the shebang, or after any mandatory comments that their boss demands be present. Definitely before any function declarations or loops. > > When it tries to parse the "echo" line, it encounters a syntax error, > > reports it, and aborts. > > > > Does a "syntax error" have to be so catastrophic as to abort the whole > script? Yes. Once the parser encounters a syntax error, it cannot assume the rest of the input is valid. It must abort.
