Skip to content

Commit add63a4

Browse files
committed
Document normalization of shell compound commands
Explain how for, while, and if blocks are treated as single structural units with recursive normalization of their internal bodies.
1 parent 451265c commit add63a4

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@ Per-command handlers add domain-specific placeholders beyond the generic
7272
rules above. For example, `curl -H` collapses to `<header>`, `grep`'s
7373
first positional becomes `<pattern>`, and `jq`'s filter becomes `<filter>`.
7474

75+
### Compound commands
76+
77+
Shell compound commands (`for`, `while`, `until`, `if`) are recognized as
78+
single structural units. Internal separators (`;`, `&&`, `|`) inside the
79+
compound don't split it apart, and the body is recursively normalized:
80+
81+
```
82+
$ shellshape "for cmd in doctor test show stats; do python3 app \$cmd --help; done"
83+
for cmd in <val>+ ; do python3 app <arg>+ ; done
84+
85+
$ shellshape "if test -f /tmp/config.yml; then cat /tmp/config.yml; else echo missing; fi"
86+
if test -f <path> ; then cat <path> ; else echo <str> ; fi
87+
```
88+
89+
For-in iteration values are collapsed to `<val>+`. C-style `for ((...))` loop
90+
expressions are collapsed to `((<expr>))`. Nested compounds are handled
91+
correctly.
92+
7593
### Subshell safety
7694

7795
Subshell expressions like `$(...)` are recursively normalized but never

0 commit comments

Comments
 (0)