# 01 — Design and finalize syntax for all new features **Status:** done **Blocks:** #02, #04, #05 ## Backtick command execution Backtick expressions return a plain table with three fields: ```lua local output = `ls -lha` print( output.code, output.stdout, output.stderr ) ``` - `output.stdout` — captured stdout as a string - `output.stderr` — captured stderr as a string - `output.code` — integer exit code - No `__tostring` metamethod — access `.stdout` explicitly ### String interpolation Backticks support `${expr}` interpolation: ```lua local dir = "/tmp" local result = `ls -lha ${dir}` local pattern = "*.lua" local result2 = `find ${dir} -name ${pattern}` ``` `${expr}` evaluates the Lua expression, converts to string, and splices it into the command string before argv parsing. ## Environment variables — `$` sigil ```lua local dir = $PWD -- getenv("PWD") → string or nil $PWD = "/" -- setenv("PWD", "/") $MY_ENV_VAR = "data" -- setenv("MY_ENV_VAR", "data") ``` - `$NAME` as an expression → `getenv("NAME")`, returns string or `nil` - `$NAME = expr` as a statement → `setenv("NAME", tostring(expr))` - `$` followed by an identifier is a new token type in the lexer - Note: `$NAME` (env var) is distinct from `${expr}` inside backticks (interpolation) ## Piping (future) ```lua local result = `ls -l` | `grep ".lua"` ``` Challenge: `|` conflicts with Lua's bitwise OR. Pipes only valid between command expressions. ## Redirection (future) ```lua `ls -l` > "output.txt" `ls -l` >> "output.txt" `cmd` 2> "err.txt" `cmd` 2>&1 `cmd` < "input.txt" ``` Challenge: `>` / `>>` conflict with Lua's comparison/shift operators. Only valid in command context.