Implement $(cmd) subcommand syntax in commands (issue #27)

Add $() for inline subcommand substitution that runs a command and
inserts its stdout (trailing newlines stripped) into the outer command
string. Supports nesting, and mixing with ${expr} and $NAME.
This commit is contained in:
Cormac Shannon
2026-03-18 09:29:51 +00:00
parent 42baabde34
commit 1766e40a68
8 changed files with 143 additions and 7 deletions

3
llex.h
View File

@@ -81,8 +81,9 @@ typedef struct LexState {
TString *brkn; /* "break" name (used as a label) */
TString *glbn; /* "global" name (when not a reserved word) */
TString *cmd_envvar; /* envvar name for $NAME in commands */
lu_byte cmd_mode; /* 0=normal, 1=backtick command, 2=interactive command */
lu_byte cmd_mode; /* 0=normal, 1=backtick, 2=interactive, 3=subcommand */
lu_byte saved_cmd_mode; /* cmd_mode to restore after interpolation */
lu_byte cmd_subcmd; /* 1 when current interpolation is $() subcommand */
} LexState;