2006/12/10
2006/08/24
Rit is a PHP like text processor that is designed for use in Plan 9. We can use full functionality of Rc. The name came from "rc in text".
rit [-Dbes] [file [arg ...]]
Date: ${date}will produce
Date: Thu Dec 23 10:17:10 JST 2004Note that we have redundant empty line after this command; this comes from two subsequent '\n's: one from command and one from our text line. Avoiding this problem we have:
${date} continues nest line ${date}$ continues same line.then the result will be:
Thu Dec 23 10:17:10 JST 2004 continues nest line Thu Dec 23 10:17:10 JST 2004 continues same line.
User: $user This is equivalent to User: ${echo -n $user}The above three lines are converted to:
User: arisawa This is equivalent to User: arisawa
This line has NL escape. $ next line.will be converted to:
This line has NL escape. next line.Most rc commands produce NL at the end. We can avoid redundant NL by putting NL escape after } and/or before NL:
${pwd}$ this line will be next of pwd line. ${pwd}$$ this line will stays in the same pwd line.the result:
/usr/arisawa/src/pegasus-2.1/rit this line will be next of pwd line. /usr/arisawa/src/pegasus-2.1/ritthis line will stays in the same pwd line.
${book='Alice in Wonder Land'}$ ${echo -n 'echo test of multi-line: line1: Carrol''s book: line2: '$book' line3: and we can use { and } in rc strings' } Back slash new line escape in Rc command will work: ${echo -n one\ two }These lines will be converted to:
echo test of multi-line: line1: Carrol's book: line2: Alice in Wonder Land line3: and we can use { and } in rc strings Back slash new line escape in Rc command will work: one two
${ if(~ $user arisawa) echo ARISAWA if not echo NOT }$will produce:
ARISAWAand
${switch($user){ case arisawa echo ARISAWA case * echo NOT }}$also produces:
ARISAWANote that { } nest is included in this example.
${# This is a comment up to NL } this is also a part of comment # this is also a comment } # invisible ${# comment line1 terminated by Rc NL escape\ comment line2 } # invisible $${# This isn't a comment but a part of text }will produce:
# invisible # invisible ${# This isn't a comment but a part of text }
$, $#are shown as it is.
Reading Rit text from stdin and using Rc command such as "read" that read data from stdin can makes a problem. Never use stdin for Rit text in web applications.
term% rit . alice bob $0 #d/0 $1 alice $2 bobwhere $0, $1, $2 are input and #d/0, alice, bob are output.
term% cat>foo $0 $1 $2 term% rit foo alice bob foo alice bob term%
term% cat>bar #!/bin/rit -s $0 $1 $2 term% chmod 755 bar term% bar alice bob ./bar alice bob term%If you want only base name of $0, you have -b option:
term% cat>bar #!/bin/rit -bs $0 $1 $2 term% chmod 755 bar term% bar alice bob bar alice bob term%
fn quit {echo exit $1 >[1=2];exit}Simple Rc "exit" does not terminate Rit
term% rit ${quit} term% echo $status term%
term% rit ${quit abcd} #<exit abc> term% echo $status rit 619: abcd term%
bind -b '#|' /tmpRc codes in Rit text is sent to /tmp/data and Rc read /tmp/data1. You can see /tmp/data and /tmp/data1 by executing:
term% rit ${ls /tmp}Stderr from Rc is used for synchronization.
foo > barand
foo | cat > barproduce same bar.
Avoiding this problem, rc function echo is predefined internally as
fn echo { if(~ $1 '-n'){ shift if(~ $"* ?*)/bin/echo -n $* } if not /bin/echo $* }