Quick reference for Plan 9 rc shell syntax. Extracted from plan9port.
var=value # assignment
var=(a b c) # list
$var # expand
$#var # count
$var(2) # index (1-based)
$$var # indirect
$"var # stringify list (join with spaces)
$var^suffix # concatenate
if(test) cmd
if not cmd
for(i in list) cmd
for(i) cmd # implicit $*
while(test) cmd
switch($var) {
case pattern
cmd
case pat1 pat2
cmd
}
fn name { body }
fn sigexit { cleanup } # trap on exit
fn sigint { } # trap ctrl-c
~ $var pattern # true if matches
~ $var *.c *.h # multiple patterns
! ~ $var pattern # negation
> file # stdout
>> file # append
< file # stdin
>[2] file # stderr
>[1=2] # merge stdout to stderr
>[2=1] # merge stderr to stdout
<{cmd} # process substitution (in)
>{cmd} # process substitution (out)
`{cmd} # split on $ifs
``(sep){cmd} # split on sep
rfork e # new env (copy)
rfork en # new env + namespace
rfork ns # new namespace only
$status # exit status of last command
exit '' # success
exit 'error msg' # failure
flag p && ... # test if -p flag was passed
getflags # parse flags
'literal' # no expansion
'' # empty string
'''' # literal single quote
# no double quotes -- use ^ for concatenation
- No double quotes (use $"var for stringify)
- path is a list, not colon-separated
- Lists are first class (not just strings)
- No export -- env is inherited via fork
- if/if not instead of if/else/elif
- ~ for pattern matching instead of [[ ]]
- fn instead of function
- $status instead of $?
- ^ for string concatenation
- No arithmetic expansion -- use expr or bc