Francisco J Ballesterosfixes0d3189f10 years agoHistory
220 lines · 2.8 KB · Text
RawDownload
# this is a comment## The prompt is ># >'s at the start of line are discarded Missing: 2>&1   # quotingecho	' quoted ` quoted 'echo	`quoted ' quoted ` # a syntax error is recovered only at top-level at the next new line# if it's a script, no further commands are executed# scripts are fully read before running any command (so they can be written)# if it's interactive, it continues reading commands{ ]	# syntax error # stdin for commands is from dev null by defaultcmd arg ... # This pipes stdin to the cmd| cmd arg ... # cmds in a single linecmd1 ; cmd2 # set vars (which are lists)x = a b cx = (a b c) # use varsecho $x $x[1] $#x # appendecho (a b c)^$x # join namesecho $^x # define a mapz = ([a b] [c] [d e f])# use a mapecho $z[a]z[a] = (a b c) # predefinedecho $argv0 $args $#args $sts # pipes and new line scapesfirstcmd | b | 	c| a | b \	 |c# set in to a's out and err, and c's in to b's erra |[in:out,err;xx:yy] b |[err] c # redirs (may name chans)a < ba > ba >> ba <[in2] ba >[out, err] ba >>ba >>[out, err] b # dup: fd[out] = fd[err]a >[out:err] # source a file< name # blocks{ a ; b }{	a	b}  # a and b outs are joined and sent to y{ a ; b } <x >y # piped blocks:a | { b ; c } | d # bga &a &xwait xwait # loop# sets x to each msg in input for each iterationcmd | words  | for x { ... }cmd | lines  | for x { ... }# conventional loop (sets x to a b c)for x a b c { ... }for x a b c { ... } <x  # whilewhile a b c { ... }while a b c { ... } >y # functionsfn x { ... } # conditional# Runs commands within each or branch# and stops as soon as the last command in a branch runs# Each or branch runs commands in order until one# fails or the last is run.# if no branch runs the last command, the sts is "false"cond {	cmd1.1	...	cmd1.n} or {	cmd2.1	...	cmd2.n} or {	cmdn.1	...	cmdn.n} # builtinscdexitexit stssleep 5flagflag +x -yztype sleep # interpolation, each msg is taken as a wordecho <{a b c}echo <{a b c|lines}echo <{a b c|words}echo <{a b c|full} # here-pipes (replaced by names for chans)diff <[in]{lf /a,} <[in2:out,err]{lf /b,}split a >[out]{cmd1} >[out2]{cmd2}  #### more examples, for testing, mostly. ####   # this is a comment#a b c ; x y c# a b c ( d e f)	-> syntax errora ^ (d e f)d e g^(a b)$a^(d $e $#g)$a[$e]# map([a b] [c d w] [x])# ([a b] [c d w] [x]) ^ c is a syntax error a b c < a >[d] ba &xa<2 | b |[x] c &z {a ; b } <x &{	a	b} # %'s are discarded %% % no prompts { { a } b ;c } for x y c {	a ; b}while a b c {	d e f}fn x {	d e f} cond {	a b c	d e} or {	a d c	x y} < a &x # this is an input pipe namediff <[x]{b ; c} # an output pipe namediff >[a]{x} >[b]{y} # this is substitutionecho <{b ; c} | a a[$x] = 5x = (a b c)^c $^a[3] < name {  true }