Files
lush/issues/01-syntax-design.md
Cormac Shannon db6f39a2a4 Add project issues for lush (Lua + shell) features
Defines syntax decisions and implementation plan across 7 issues:
- backtick command execution returning {code, stdout, stderr}
- ${expr} interpolation in backticks
- $SIGIL env var read/write
- argv parsing, piping, and redirection (future)
2026-02-18 19:08:59 +00:00

1.7 KiB

01 — Design and finalize syntax for all new features

Status: resolved Blocks: #02, #04, #05

Backtick command execution

Backtick expressions return a plain table with three fields:

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:

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

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)

local result = `ls -l` | `grep ".lua"`

Challenge: | conflicts with Lua's bitwise OR. Pipes only valid between command expressions.

Redirection (future)

`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.