Rc - The Plan 9 Shell

16

Click here to load reader

description

I give a brief overview of the rc shell from the Plan 9 operating system. Rc is also available on Mac and Linux OSs via plan9port.

Transcript of Rc - The Plan 9 Shell

Page 1: Rc - The Plan 9 Shell

RcThe Plan 9 OS Shell

Page 2: Rc - The Plan 9 Shell

Goals● Improve on other UNIX shells● Better parsing● Be like Bourne/BASH but with "less

idiosyncratic syntax"[1]○ Syntax draws on C rather than Algol 68 (brackets

rather than keywords) if(test -f junk) rm junkif test -f junk; then rm junk; fi

Page 3: Rc - The Plan 9 Shell

Basicsdatecat /lib/news/buildwho >user.namesrm -r junk || echo rm failed!

Page 4: Rc - The Plan 9 Shell

Quotingrm 'some file' # with spaces echo 'How''s your father?' # doubled apostrophes for lit.

Page 5: Rc - The Plan 9 Shell

Patterns and Wildcardsls foo* # foo_bar foo_baz foo ls foo? # fool foot foo_ ls foo[a-z] # fool foot ls foo[~a-z] # foo_

Page 6: Rc - The Plan 9 Shell

Variables# values are lists of strings path=(. /bin) # list of single string user=tdfont=/font/bit/pelm/ascii.9.font

Page 7: Rc - The Plan 9 Shell

Variables continuedecho $path # => echo . /bin echo $path(2) # => echo /binecho $path(2 1 2) # echo /bin . /bin # note difference:empty=()null=''

Page 8: Rc - The Plan 9 Shell

Arguments$* # argument list$1 # same as $*(1)

Page 9: Rc - The Plan 9 Shell

Concatenation^ is the concat. operator echo (a b c)^(1 2 3)# => echo a1 b2 c3

src=(main subr io)cc $src^.c# => cc main.c subr.c io.c

Page 10: Rc - The Plan 9 Shell

Use command outputcat `{ls -tr | sed 10q} ...output contents of ten most recent files (ascending) (btw: that's a backtick, or leftquote, we lispers would say quasiquote)

Page 11: Rc - The Plan 9 Shell

The gloves come off..."Rc has syntax for some kinds of non-linear but treelike pipelines."[1] cmp <{old} <{new} ...cmp's input is old's and new's output in parallel

Page 12: Rc - The Plan 9 Shell

Examples (1)for(i){

if(test -f /tmp/$i)echo $i already in /tmp

if notcp $i /tmp

}

Page 13: Rc - The Plan 9 Shell

Examples (2)ps1=’% ’tab=’ ’fn cd{ builtin cd $1 && switch($#*){ case 0 dir=$home prompt=($ps1 $tab)

case * switch($1) case /* dir=$1 prompt=(‘{basename ‘{pwd}}^$ps1 $tab) case */* ..* dir=() prompt=(‘{basename ‘{pwd}}^$ps1 $tab) case * dir=() prompt=($1^$ps1 $tab) } }}

Page 14: Rc - The Plan 9 Shell

Examples (2) fn pwd{ if(~ $#dir 0) dir=‘{/bin/pwd} echo $dir}

Page 15: Rc - The Plan 9 Shell

There's more● functions● nice file descriptor redirection● global and local variables

Page 16: Rc - The Plan 9 Shell

References1. http://plan9.bell-labs.com/sys/doc/rc.html2. https://en.wikipedia.org/wiki/Rc3. http://plan9.bell-labs.

com/magic/man2html/1/rc4.