9797/<<[ ] * [-\\ '] * [A-Za-z0-9_] / {
9898 s /^ \( . * \) <<[ ] * [-\\ '] * \( [A-Za-z0-9_][A-Za-z0-9_] * \) '* /<\2 >\1 << /
9999 s /[ ] * << //
100- : hereslurp
100+ : hered
101101 N
102102 /^ <\( [^ >] * \) >. * \n [ ] * \1 [ ] * $ /! {
103103 s /\n . * $ //
104- b hereslurp
104+ b hered
105105 }
106106 s /^ <[^ >] * > //
107107 s /\n . * $ //
131131b
132132
133133: subshell
134- # bare "(" line?
134+ # bare "(" line? -- stash for later printing
135135/^ [ ] * ( [ ] * $ / {
136- # stash for later printing
137136 h
138137 b nextline
139138}
@@ -150,7 +149,7 @@ s/.*\n//
150149
151150: slurp
152151# incomplete line "...\"
153- /\\ $ /b incomplete
152+ /\\ $ /b icmplte
154153# multi-line quoted string "...\n..."?
155154/" /b dqstring
156155# multi-line quoted string '...\n...'? (but not contraction in string "it's")
@@ -172,7 +171,7 @@ s/.*\n//
172171 /"[^ "] * #[^ "] * " /! s /[ ] #. * $ //
173172}
174173# one-liner "case ... esac"
175- /^ [ ] * case[ ] * .. * esac /b checkchain
174+ /^ [ ] * case[ ] * .. * esac /b chkchn
176175# multi-line "case ... esac"
177176/^ [ ] * case[ ] .. * [ ] in /b case
178177# multi-line "for ... done" or "while ... done"
@@ -201,32 +200,32 @@ s/.*\n//
201200/^ [ ] * fi[ ] * [<>|] /b done
202201/^ [ ] * fi[ ] * ) /b done
203202# nested one-liner "(...) &&"
204- /^ [ ] * ( . * ) [ ] * &&[ ] * $ /b checkchain
203+ /^ [ ] * ( . * ) [ ] * &&[ ] * $ /b chkchn
205204# nested one-liner "(...)"
206- /^ [ ] * ( . * ) [ ] * $ /b checkchain
205+ /^ [ ] * ( . * ) [ ] * $ /b chkchn
207206# nested one-liner "(...) >x" (or "2>x" or "<x" or "|x")
208- /^ [ ] * ( . * ) [ ] * [0-9] * [<>|] /b checkchain
207+ /^ [ ] * ( . * ) [ ] * [0-9] * [<>|] /b chkchn
209208# nested multi-line "(...\n...)"
210209/^ [ ] * ( /b nest
211210# multi-line "{...\n...}"
212211/^ [ ] * { /b block
213212# closing ")" on own line -- exit subshell
214- /^ [ ] * ) /b closesolo
213+ /^ [ ] * ) /b clssolo
215214# "$((...))" -- arithmetic expansion; not closing ")"
216- /\$ (( [^ )][^ )] * )) [^ )] * $ /b checkchain
215+ /\$ (( [^ )][^ )] * )) [^ )] * $ /b chkchn
217216# "$(...)" -- command substitution; not closing ")"
218- /\$ ( [^ )][^ )] * ) [^ )] * $ /b checkchain
217+ /\$ ( [^ )][^ )] * ) [^ )] * $ /b chkchn
219218# multi-line "$(...\n...)" -- command substitution; treat as nested subshell
220219/\$ ( [^ )] * $ /b nest
221220# "=(...)" -- Bash array assignment; not closing ")"
222- /=( /b checkchain
221+ /=( /b chkchn
223222# closing "...) &&"
224223/) [ ] * &&[ ] * $ /b close
225224# closing "...)"
226225/) [ ] * $ /b close
227226# closing "...) >x" (or "2>x" or "<x" or "|x")
228227/) [ ] * [<>|] /b close
229- : checkchain
228+ : chkchn
230229# mark suspect if line uses ";" internally rather than "&&" (but not ";" in a
231230# string and not ";;" in one-liner "case...esac")
232231/; /{
245244b slurp
246245
247246# found incomplete line "...\" -- slurp up next line
248- : incomplete
247+ : icmplte
249248N
250249s /\\ \n //
251250b slurp
@@ -283,11 +282,11 @@ bfolded
283282: heredoc
284283s /^ \( . * \) <<[ ] * [-\\ '] * \( [A-Za-z0-9_][A-Za-z0-9_] * \) '* /<\2 >\1 << /
285284s /[ ] * << //
286- : hereslurpsub
285+ : heredsub
287286N
288287/^ <\( [^ >] * \) >. * \n [ ] * \1 [ ] * $ /! {
289288 s /\n . * $ //
290- b hereslurpsub
289+ b heredsub
291290}
292291s /^ <[^ >] * > //
293292s /\n . * $ //
317316# is 'done' or 'fi' cuddled with ")" to close subshell?
318317/done. * ) /b close
319318/fi. * ) /b close
320- b checkchain
319+ b chkchn
321320
322321# found nested multi-line "(...\n...)" -- pass through untouched
323322: nest
324323x
325- : nestslurp
324+ : nstslurp
326325n
327326# closing ")" on own line -- stop nested slurp
328- /^ [ ] * ) /b nestclose
327+ /^ [ ] * ) /b nstclose
329328# comment -- not closing ")" if in comment
330- /^ [ ] * # /b nestcontinue
329+ /^ [ ] * # /b nstcnt
331330# "$((...))" -- arithmetic expansion; not closing ")"
332- /\$ (( [^ )][^ )] * )) [^ )] * $ /b nestcontinue
331+ /\$ (( [^ )][^ )] * )) [^ )] * $ /b nstcnt
333332# "$(...)" -- command substitution; not closing ")"
334- /\$ ( [^ )][^ )] * ) [^ )] * $ /b nestcontinue
333+ /\$ ( [^ )][^ )] * ) [^ )] * $ /b nstcnt
335334# closing "...)" -- stop nested slurp
336- /) /b nestclose
337- : nestcontinue
335+ /) /b nstclose
336+ : nstcnt
338337x
339- b nestslurp
340- : nestclose
338+ b nstslurp
339+ : nstclose
341340s /^ />> /
342341# is it "))" which closes nested and parent subshells?
343342/) [ ] * ) /b slurp
344- b checkchain
343+ b chkchn
345344
346345# found multi-line "{...\n...}" block -- pass through untouched
347346: block
348347x
349348n
350349# closing "}" -- stop block slurp
351- /} /b checkchain
350+ /} /b chkchn
352351b block
353352
354353# found closing ")" on own line -- drop "suspect" from final line of subshell
355354# since that line legitimately lacks "&&" and exit subshell loop
356- : closesolo
355+ : clssolo
357356x
358357s /? !AMP? ! //
359358p
0 commit comments