Rc - The Plan 9 Shell
Click here to load reader
-
Upload
twopoint718 -
Category
Technology
-
view
1.666 -
download
1
description
Transcript of Rc - The Plan 9 Shell
![Page 1: Rc - The Plan 9 Shell](https://reader037.fdocuments.us/reader037/viewer/2022100311/55646a82d8b42a90338b52f7/html5/thumbnails/1.jpg)
RcThe Plan 9 OS Shell
![Page 2: Rc - The Plan 9 Shell](https://reader037.fdocuments.us/reader037/viewer/2022100311/55646a82d8b42a90338b52f7/html5/thumbnails/2.jpg)
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](https://reader037.fdocuments.us/reader037/viewer/2022100311/55646a82d8b42a90338b52f7/html5/thumbnails/3.jpg)
Basicsdatecat /lib/news/buildwho >user.namesrm -r junk || echo rm failed!
![Page 4: Rc - The Plan 9 Shell](https://reader037.fdocuments.us/reader037/viewer/2022100311/55646a82d8b42a90338b52f7/html5/thumbnails/4.jpg)
Quotingrm 'some file' # with spaces echo 'How''s your father?' # doubled apostrophes for lit.
![Page 5: Rc - The Plan 9 Shell](https://reader037.fdocuments.us/reader037/viewer/2022100311/55646a82d8b42a90338b52f7/html5/thumbnails/5.jpg)
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](https://reader037.fdocuments.us/reader037/viewer/2022100311/55646a82d8b42a90338b52f7/html5/thumbnails/6.jpg)
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](https://reader037.fdocuments.us/reader037/viewer/2022100311/55646a82d8b42a90338b52f7/html5/thumbnails/7.jpg)
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](https://reader037.fdocuments.us/reader037/viewer/2022100311/55646a82d8b42a90338b52f7/html5/thumbnails/8.jpg)
Arguments$* # argument list$1 # same as $*(1)
![Page 9: Rc - The Plan 9 Shell](https://reader037.fdocuments.us/reader037/viewer/2022100311/55646a82d8b42a90338b52f7/html5/thumbnails/9.jpg)
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](https://reader037.fdocuments.us/reader037/viewer/2022100311/55646a82d8b42a90338b52f7/html5/thumbnails/10.jpg)
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](https://reader037.fdocuments.us/reader037/viewer/2022100311/55646a82d8b42a90338b52f7/html5/thumbnails/11.jpg)
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](https://reader037.fdocuments.us/reader037/viewer/2022100311/55646a82d8b42a90338b52f7/html5/thumbnails/12.jpg)
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](https://reader037.fdocuments.us/reader037/viewer/2022100311/55646a82d8b42a90338b52f7/html5/thumbnails/13.jpg)
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](https://reader037.fdocuments.us/reader037/viewer/2022100311/55646a82d8b42a90338b52f7/html5/thumbnails/14.jpg)
Examples (2) fn pwd{ if(~ $#dir 0) dir=‘{/bin/pwd} echo $dir}
![Page 15: Rc - The Plan 9 Shell](https://reader037.fdocuments.us/reader037/viewer/2022100311/55646a82d8b42a90338b52f7/html5/thumbnails/15.jpg)
There's more● functions● nice file descriptor redirection● global and local variables
![Page 16: Rc - The Plan 9 Shell](https://reader037.fdocuments.us/reader037/viewer/2022100311/55646a82d8b42a90338b52f7/html5/thumbnails/16.jpg)
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.