On this page:
3.1 Running programs
3.2 Piping
3.3 Redirection

3 Shell

The goal for the shell command line was to try to have familiar syntax as to what you’d use in bash, while making a few improvements. To do this Rain changes the current readtable so that whenever a { is detected it parses the source differently until the closing }. In Racket (, [, and { are all equivalent and since in my experience {}’s aren’t used much I decided to repurpose them to delimit shell lang. Any code in shell-lang gets converted to valid Racket code, and you can combine Racket and shell by including Racket variables or expressions inside shell as you can see in the section below.

For more information on shell lang see Sh Lang.

3.1 Running programs

To run a program, enclose it and any arguments inside curly braces {}.

Example:

{ls}

You can use Racket variables inside {}:

(define path "docs")

{ls docs}

and use sh lang inside Racket functions:

(define (my-ls filename) {ls filename})

(my-ls "interpreter.rkt")

as well as use the result of expressions:

{ls (map (lambda (x) (string-append x ".rkt")) ’("shell" "builtins"))}

3.2 Piping

Piping takes the output from one program and uses it as the input for the next without having to create a temporary file to store the intermediate results. So instead of having to do:

{ls > ls_results}

{grep rkt ls_results > grep_results}

{sort grep_results}

you can do:

{ls | grep rkt | sort}

3.3 Redirection

Programs have three standard streams, input (stdin), output (stdout) and error (stderr). Normally when you run a program in the terminal stdin comes from the keyboard, and stdout and stderr get displayed on the screen. With redirection you can change that, for instance you can redirect stdin to read from a file, or stdout to output to a file. The second example is useful when you want to save the resulting output of a program to read again later. To redirect in Rain:

Examples:

{ls > results.txt}

{cat < results.txt | sort -r > sorted.txt}

{wget invalid://add.re/ss ^ err.txt}