RC(1)

πŸ“¦
version 1.7.4+97.gceb59bb Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu questing

RC(1) ✨

okay bestie, welcome to the rc(1) glow-up πŸ’– this is the General Commands Manual page for rc, and I'm about to make it make sense.

🌸 NAME 🌸

rc β€” it's a shell 🐚

✨ SYNOPSIS ✨

rc [-deiIlnopsvx] [-c command] [arguments]

πŸ’– DESCRIPTION πŸ’–

okay so rc is a command interpreter and a whole programming language, lowkey like sh(1) but with more main character energy. It's based on the AT&T Plan 9 shell of the same name β€” yes, the vibes are inherited πŸ‘‘

The shell serves a C-like syntax (way more than the C shell does, fr fr), plus a genuinely powerful mechanism for manipulating variables. It's reasonably small and reasonably fast, especially when you put it next to contemporary shells. Its use is intended to be interactive, but the language lends itself well to scripts too. iykyk.


πŸ’… OPTIONS πŸ’…

  • -c0 β€” if -c0 shows up, commands get executed from the argument right after it. Any further arguments to rc get placed in $*.0 So like:
rc -c 'echo $*' 1 2 30

prints out

1 2 30
  • -d0 β€” this flag makes rc not ignore SIGQUIT0 or SIGTERM.0 So rc can be made to dump core if you send it SIGQUIT.0 This is only useful for debugging rc β€” it's a dev tool, not a lifestyle, bestie.
  • -e0 β€” if -e0 is present, rc will exit if any command fails (exits with non-zero status). BUT. rc -e does not exit if a conditional fails. A conditional is the test of an if ()0 command, the test of a while ()0 command, or the left hand side of the ||0 or the &&0 operator. periodt.
  • -i0 β€” if -i0 is present, or if the input to rc is from a terminal (as determined by isatty(3)), then rc will be in interactive mode. That means a prompt (from $prompt(1))0) gets printed before an input line is taken, and rc will ignore SIGINT.0
  • -I0 β€” if -I0 is present, or if the input to rc is not from a terminal, then rc will not be in interactive mode. No prompts get printed, and SIGINT0 will cause rc to exit.
  • -l0 β€” if -l0 is present, or if rc's argv[0][0]0 is a dash (-),0 then rc will behave as a login shell. That means it runs commands from $home/.rcrc,0 if this file exists, before reading any other input. ✨
  • -n0 β€” this flag makes rc read its input and parse it, but not execute any commands. Chef's kiss for syntax checking on scripts. If you use it together with the -x0 flag, rc will print each command as it's parsed, in a form similar to the one used for exporting functions into the environment.
  • -o0 β€” this flag prevents the usual practice of trying to open /dev/null0 on file descriptors 0, 1, and 2, if any of those descriptors are inherited closed.
  • -p0 β€” this flag prevents rc from initializing shell functions from the environment. It lets rc run in a protected mode, where it becomes more difficult for an rc script to be subverted by placing false commands in the environment. (Note that having this flag does not mean it's safe to run setuid rc scripts β€” the usual caveats about the setuid bit still apply. 🚨)
  • -s0 β€” this flag makes rc read from standard input. Any arguments get placed in $*.0
  • -v0 β€” this flag makes rc echo its input to standard error as it's read.
  • -x0 β€” this flag makes rc print every command on standard error before it's executed. Super useful for debugging rc scripts.

πŸ‘‘ COMMANDS πŸ‘‘

A simple command is a sequence of words, separated by white space (space and tab) characters, that ends with a newline, semicolon (;),0 or ampersand (&).0 The first word of a command is the name of that command. If the name begins with /,0 ./,0 or ../,0 then the name is used as an absolute path name referring to an executable file. Otherwise, the command's name is looked up in a table of shell functions, builtin commands, or as a file in the directories named by $path.0

🌈 Background Tasks 🌈

A command ending with &0 is run in the background β€” meaning the shell returns immediately instead of waiting for the command to complete. Background commands have /dev/null0 connected to their standard input, unless an explicit redirection for standard input is used. slay, multitasking πŸ’…

πŸ¦‹ Subshells πŸ¦‹

A command prefixed with an at-sign (@)0 is executed in a subshell. This insulates the parent shell from the effects of state changing operations like a cd or a variable assignment. For example:

@ {cd ..; make}0

will run make(1) in the parent directory (..),0 but leaves the shell running in the current directory. iconic behaviour honestly.

πŸŽ€ Line continuation πŸŽ€

A long logical line may be continued over several physical lines by terminating each line (except the last) with a backslash (\).0 The backslash-newline sequence is treated as a space. A backslash is not otherwise special to rc. (In addition, inside quotes a backslash loses its special meaning even when it is followed by a newline.)

πŸ’œ Quoting πŸ’œ

rc interprets several characters specially; special characters automatically terminate words. Here's the special squad:

# ; & | ^ $ ` ' { } ( ) < >0

The single quote (')0 prevents special treatment of any character other than itself. All characters β€” including control characters, newlines, and backslashes β€” between two quote characters are treated as an uninterpreted string. A quote character itself may be quoted by placing two quotes in a row. The minimal sequence needed to enter the quote character is ''''.0 The empty string is represented by ''.0 So:

echo 'What''s the plan, Stan?'0

prints out

What's the plan, Stan?0

The number sign (#)0 begins a comment in rc. All characters up to but not including the next newline are ignored. Heads up though: backslash continuation does not work inside a comment, i.e. the backslash is ignored along with everything else. no cap.

πŸ“ Grouping πŸ“

Zero or more commands may be grouped within braces (β€œ{”0 and β€œ}”),0 and are then treated as one command. Braces do not otherwise define scope β€” they're used only for command grouping. In particular, be wary of the command:

for (i) {0
    command0
} | command0

Since pipe binds tighter than for,0 this command does not perform what the user expects it to. Instead, enclose the whole for0 statement in braces:

{for (i) command} | command0

Fortunately, rc's grammar is simple enough that a (confident) user can understand it by examining the skeletal yacc(1) grammar at the end of this man page (see the section entitled GRAMMAR). you got this πŸ’ͺ

🧚 Input and output 🧚

The standard output may be redirected to a file with

command > file0

and the standard input may be taken from a file with

command < file0

Redirections can appear anywhere in the line: the word following the redirection symbol is the filename, and it must be quoted if it contains spaces or other special characters. These are all equivalent:

echo 1 2 3 > foo0
> foo echo 1 2 30
echo 1 2 > foo 30

File descriptors other than 0 and 1 may be specified too. For example, to redirect standard error to a file, use:

command >[2] file0

In order to duplicate a file descriptor, use >[n=m].0 So to redirect both standard output and standard error to the same file, use:

command > file >[2=1]0

As in sh, redirections are processed from left to right. Which means this sequence:

command >[2=1] > file0

is usually a mistake. It first duplicates standard error to standard output; then it redirects standard output to a file, leaving standard error wherever standard output originally was. πŸ’€

To close a file descriptor that may be open, use >[n=].0 For example, to close file descriptor 7:

command >[7=]0

Note that no spaces may appear in these constructs:

command > [2] file0

That would send the output of the command to a file named [2],0 with the intended filename appearing in the command's argument list. oops.

In order to place the output of a command at the end of an already existing file, use:

command >> file0

If the file does not exist, then it is created.

β€œHere documents” are supported as in sh with the use of

command << 'eof-marker'0

Subsequent lines form the standard input of the command, till a line containing just the marker β€” in this case eof-marker,0 β€” is encountered.

If the end-of-file marker is enclosed in quotes, then no variable substitution occurs inside the here document. Otherwise, every variable is substituted by its space-separated-list value (see Flat Lists, below), and if a ^0 character follows a variable name, it is deleted. This allows the unambiguous use of variables adjacent to text, as in

$variable^follow0

To include a literal $0 in a here document when an unquoted end-of-file marker is being used, enter it as $$.0

Additionally, rc supports β€œhere strings”, which are like here documents, except that input is taken directly from a string on the command line. Their use is illustrated here:

cat <<< 'this is a here string' | wc0

(This feature enables rc to export functions using here documents into the environment; the author does not expect users to find this feature useful. πŸ’€)

⭐ Pipes ⭐

Two or more commands may be combined in a pipeline by placing the vertical bar (|)0 between them. The standard output (file descriptor 1) of the command on the left is tied to the standard input (file descriptor 0) of the command on the right. The notation |[n=m]0 indicates that file descriptor n of the left process is connected to file descriptor m of the right process. |[n]0 is a shorthand for |[n=0].0 As an example, to pipe the standard error of a command to wc(1), use:

command |[2] wc0

As with file redirections, no spaces may occur in the construct specifying numbered file descriptors.

The exit status of a pipeline is considered true if and only if every command in the pipeline exits true. all or nothing, bestie πŸ’…

🌸 Commands as Arguments 🌸

Some commands, like cmp(1) or diff(1), take their arguments on the command line, and do not read input from standard input. It's convenient sometimes to build nonlinear pipelines so that a command like cmp can read the output of two other commands at once. rc does it like this:

cmp <{command} <{command}0

compares the output of the two commands in braces. Note: since this form of redirection is implemented with some kind of pipe, and since one cannot lseek(2) on a pipe, commands that use lseek(2) will hang. For example, some versions of diff(1) use lseek(2) on their inputs. 🚨

Data can be sent down a pipe to several commands using tee(1) and the output version of this notation:

echo hi there | tee >{sed 's/^/p1 /'} >{sed 's/^/p2 /'}0

✨ CONTROL STRUCTURES ✨

okay bestie, so here's the tea on how to control the flow in rc:


πŸ’… If-Else Statements πŸ’…

so you wanna do an if-else? say less. here's the vibe:

if (test) {0
    cmd
} else cmd0

the test runs first, and if its return status is zero, the first command runs. otherwise, the second one runs. braces are not mandatory around the commands. BUT β€” and this is important β€” an else0 statement is only valid if it follows a close-brace on the same line. otherwise, the if0 is taken to be a simple-if:

if (test)0
    command0

πŸŒ€ While and For Loops πŸŒ€

while (test) cmd0 β€” rc runs the test and then keeps doing the cmd as long as the test is true. like, it's giving persistence.

for (var in list) cmd0 β€” rc sets var to each element of list (which can have variables and backquote substitutions) and runs cmd. if you omit β€œin0 list”, then rc will set var to each element of $*.0. for example:

for (i in `{ls -F | grep '\*$' | sed 's/\*$//'}) { commands }0

will set $i0 to the name of each file in the current directory that is executable. slay.


πŸ”€ Switch πŸ”€

switch (list) { case ... }0 β€” rc looks inside the braces after a switch0 for statements that start with the word case.0 if any of the patterns following case0 match the list you gave to switch,0 then the commands up until the next case0 statement get executed. the metacharacters *,0 [0 or ?0 should not be quoted; matching only happens against the strings in list, not against file names. (matching for case statements is the same as for the ~0 command.) periodt.


🧠 Logical Operators 🧠

there are a bunch of operators in rc that depend on the exit status of a command. iykyk.

command && command0 β€” runs the first command, and then runs the second command if and only if the first command exits with a zero exit status (β€œtrue” in Unix).

command || command0 β€” runs the first command, and then runs the second command if and only if the first command exits with a nonzero exit status (β€œfalse” in Unix).

! command0 β€” negates the exit status of a command. it's giving uno reverse card. πŸ™ƒ


🌈 PATTERN MATCHING 🌈

there are two forms of pattern matching in rc. one is the classic shell globbing. this happens when matching file names in argument lists:

command argument argument ...0

when the characters *,0 [0 or ?0 show up in an argument or command, rc treats the argument as a pattern to match against files. (unlike other shells, rc will only do pattern matching if a metacharacter occurs unquoted and literally in the input. so:

foo='*'0
echo $foo0

will always echo just a star. for non-literal metacharacters to be expanded, you gotta use an eval0 statement to rescan the input.) pattern matching works like this: a *0 matches any number (including zero) of characters. a ?0 matches any single character, and a [0 followed by a bunch of characters followed by a ]0 matches a single character in that class. the rules for character class matching are the same as for ed(1), except that character class negation uses the tilde ((~),0) not the caret ((^),0) because the caret already means something else in rc.

rc also matches patterns against strings with the ~0 command:

~ subject pattern pattern ...0

the ~0 command succeeds (sets $status0 to zero) if and only if one of the patterns0 matches subject.0 so:

~ foo f*0

succeeds (sets status to zero), while:

~ bar f*0

fails (sets status to one).

the null list is matched by the null list, so:

~ $foo ()0

checks whether $foo0 is empty or not. because rc doesn't have hierarchical lists, the emptiness test can't be combined with other tests. to test whether $foo0 is empty, or one of the strings nada0 or rien,0 do not write:

~ $x () nada rien # WRONG means the same as: ~ $x nada rien0

instead write:

~ $x () || ~ $x nada rien0

another way to test if $foo0 is empty is:

~ $#foo 00

note that inside a ~0 command rc does not match patterns against file names, so you don't need to quote the characters *,0 [0 and ?.0 however, rc does expand the subject against filenames if it contains metacharacters. so the command:

~ * ?0

succeeds if any of the files in the current directory have a single-character name.

if the ~0 command is given a list as its first argument, then a successful match against any of the elements of that list will cause ~0 to succeed. for example:

~ (foo goo zoo) z*0

is true. no cap. πŸ’―

πŸ’– LISTS AND VARIABLES πŸ’–

okay bestie, this is the part where it gets good. πŸ¦‹

The primary data structure in rc is the list, which is a sequence of words. Parentheses group lists together. The empty list is (). And like β€” lists have no hierarchical structure, okay? A list inside another list gets expanded so the outer list contains all the elements of the inner list. So all of these are literally the same thing:

one two three

(one two three)

((one) () ((two three)))

Now, the thing that trips everyone up: the null string '' and the null list () are two very different things. Assigning the null string to a variable is a perfectly valid operation, but it does not remove its definition.

null = '' empty = () echo $#null $#empty

produces the output

1 0

see? one element vs zero. iconic difference honestly.

✨ List Concatenation ✨

Two lists get joined by the concatenation operator (^).

The rules are: if the two lists have the same number of elements, then concatenation is pairwise:

echo (a- b- c-)^(1 2 3)

produces the output

a-1 b-2 c-3

Otherwise, at least one of the lists must have a single element, and then the concatenation is distributive:

cc -^(O g c) (malloc alloca)^.c

has the effect of performing the command

cc -O -g -c malloc.c alloca.c

A single word is a list of length one, so

echo foo^bar

produces the output

foobar

πŸŽ€ Free Carets πŸŽ€

rc inserts carets (concatenation operators) for free in certain situations, purely to save you some typing. no cap, it's just doing you a favor. πŸ’…

For example, that last example above could also be typed in as:

opts=(O g c) files=(malloc alloca) cc -$opts $files.c

rc takes care to insert a free caret between the - and $opts, as well as between $files and .c. And the rule for free carets is: if a word or keyword is immediately followed by another word, keyword, dollar-sign or backquote, then rc inserts a caret between them.

🌸 Variables 🌸

A list may be assigned to a variable, using the notation:

var = list

The special variable * may also be assigned to using this notation; rc has no set builtin.

Any non-empty sequence of characters β€” except a sequence including only digits β€” may be used as a variable name. Any character except = may be used, but special characters must be quoted. And psst: all user-defined variables are exported into the environment.

The value of a variable is referenced with the dollar ($) operator:

$var

Any variable which has not been assigned a value returns the null list, (), when referenced. Multiple references are allowed:

a = foo
b = a
echo $ $ b

prints

foo

A variable's definition may also be removed by assigning the null list to a variable:

var=()

okay so for β€œfree careting” to work correctly, rc has to make certain assumptions about what characters may appear in a variable name. rc assumes a variable name consists only of alphanumeric characters, underscore (_) and star (*). To reference a variable with other characters in its name, quote the variable name. Thus:

echo $'we$Ird:Variab!le'

πŸ’œ Local Variables πŸ’œ

Any number of variable assignments may be made local to a single command by typing:

a=foo b=bar ... command

The command may be a compound command, so for example:

path=. ifs=() {
    ...
}

sets path to . and removes ifs for the duration of one long compound command. sustainable slay.

πŸ¦‹ Variable Subscripts πŸ¦‹

Variables may be subscripted with the notation

$var(n)

where n is a list of integers (origin 1 β€” not zero, bestie, do not come at me with zero). The opening parenthesis must immediately follow the variable name. The list of subscripts need not be in order or even unique. Thus,

a=(one two three)
echo $a(3 3 3)

prints

three three three

If n references a nonexistent element, then $var(n) returns the null list. The notation $n, where n is an integer, is a shorthand for $*(n). Thus, rc's arguments may be referred to as $1, $2, and so on.

Note also that the list of subscripts may be given by any of rc's list operations:

$var(`{awk 'BEGIN{for(i=1;i<=10;i++)print i;exit; }'})

returns the first 10 elements of $var.

To count the number of elements in a variable, use

$#var

This returns a single-element list, with the number of elements in $var.

πŸ’… Flat Lists πŸ’…

In order to create a single-element list from a multi-element list, with the components space-separated, use the dollar-caret ($^) operator:

$^var

This is useful when the normal list concatenation rules need to be bypassed. For example, to append a single period at the end of $path, use:

echo $^path.

For compatibility with the Plan 9 rc,

$"var

is accepted as a synonym for dollar-caret.

⭐ Backquote Substitution ⭐

A list may be formed from the output of a command by using backquote substitution:

`{ command }

returns a list formed from the standard output of the command in braces. $ifs is used to split the output into list elements. By default, $ifs has the value space-tab-newline.

The braces may be omitted if the command is a single word. Thus `ls may be used instead of `{ls}. This last feature can be used to create shortcuts by defining functions that expand to useful argument lists. For example:

fn src { echo *.[chy] }

followed by

wc `src

This will print out a word-count of all C source files in the current directory. obsessed with this trick, genuinely. 🫢

In order to override the value of $ifs for a single backquote substitution, use:

`` (ifs-list) { command }

$ifs will be temporarily ignored and the command's output will be split as specified by the list following the double backquote. For example:

`` ($nl :) {cat /etc/passwd}

splits up /etc/passwd into fields.

As a convenience, rc defines $nl to contain the newline character, and $tab to contain the tab character. Thus, if you want to process everything in the current directory, but in a random order, you could use:

for (f in `` $nl {ls | shuf}) { ... process $f }

This will correctly handle filenames that contain spaces. 😭 the way that this is the dream, actually.

note: rc scripts that use backquote substitution should avoid relying on the default values of $ifs, $nl, or $tab. Instead, they should explicitly set what they need. fr fr, do not trust the defaults in a script. πŸ™ˆ

πŸŽ€ SPECIAL VARIABLES πŸŽ€

okay so rc has a whole lil VIP lounge of variables it knows about, and it treats them extra special, no cap. Here's the key to reading the list below, bestie:

  • β€œdefault” β€” rc hands this variable a default value right at startup. πŸ’…
  • β€œno-export” β€” this one is never exported. ever. it stays home. πŸ™ˆ
  • β€œread-only” β€” try to set it and... nothing happens. the attempt silently has no effect. 😭
  • β€œalias” β€” the variable is aliased to the same name in capitals. so like, an assignment to $cdpath causes an automatic assignment to $CDPATH, and vice-versa. πŸ¦‹

So if $CDPATH is set when rc is started, its value gets imported into $cdpath. $cdpath and $path are rc lists; $CDPATH and $PATH are colon-separated lists. And only the names spelt in capitals get exported into the environment. periodt. πŸ‘‘


  • * (no-export) β€” the argument list of rc. $1, $2, etc. are the same as $*(1), $*(2), etc. it's giving the same thing in two outfits. ✨
  • 0 (default no-export) β€” $0 holds the value of argv[0] with which rc was invoked. ALSO, $0 gets set to the name of a function for the duration of that function's execution, and $0 is also set to the name of the file being interpreted for the duration of a . command. $0 is not an element of $*, and is never treated as one. 🫢
  • apid (no-export) β€” the process ID of the last process started in the background.
  • apids (no-export read-only) β€” a list whose elements are the process IDs of all background processes which are still alive, or which have died and have not been waited for yet. 🧚
  • bqstatus (no-export) β€” the exit status of the rc forked to execute the most recent backquote substitution. heads up though: unlike $status, $bqstatus is always a single element list (peep EXIT STATUS below). for example:
echo foo |grep bar; whatis status

prints

status=(0 1)

whereas

x=`{echo foo |grep bar}; whatis bqstatus

prints

bqstatus=1
  • cdpath (alias) β€” a list of directories to search for the target of a cd command. the empty string stands for the current directory. ngl, note that if the $cdpath variable does not contain the current directory, then the current directory will not be searched; this allows directory searching to begin in a directory other than the current directory. πŸ“
  • history β€” $history contains the name of a file to which commands are appended as rc reads them. this facilitates the use of a stand-alone history program (such as history(1)) which parses the contents of the history file and presents them to rc for reinterpretation. if $history is not set, then rc does not append commands to any file. πŸ’œ
  • home (alias) β€” the default directory for the builtin cd command, and the directory in which rc looks to find its initialization file, .rcrc, if rc has been started up as a login shell. 🌸
  • ifs (default) β€” the internal field separator, used for splitting up the output of backquote commands for digestion as a list. on startup, rc assigns the list containing the characters space, tab, and newline to $ifs. ✨
  • nl (default) β€” contains the newline character (see Backquote substitution above).
  • path (alias) β€” this is a list of directories to search in for commands. the empty string stands for the current directory. if neither $PATH nor $path is set at startup time, $path assumes a default value suitable for your system. this is typically (/usr/local/bin /usr/bin /usr/ucb /bin .) πŸ”₯
  • pid (default no-export) β€” on startup, $pid is initialized to the numeric process ID of the currently running rc. πŸŽ€
  • prompt (default) β€” this variable holds the two prompts (in list form, of course πŸ’…) that rc prints. $prompt(1) is printed before each command is read, and $prompt(2) is printed when input is expected to continue on the next line. rc sets $prompt to ('; ' '') by default. the reason for this is that it enables an rc user to grab commands from previous lines using a mouse, and to present them to rc for re-interpretation; the semicolon prompt is simply ignored by rc. the null $prompt(2) also has its justification: an rc script, when typed interactively, will not leave $prompt(2)'s on the screen, and can therefore be grabbed by a mouse and placed directly into a file for use as a shell script, without further editing being necessary. iconic behaviour honestly. πŸ–±οΈ
  • prompt (function) β€” if this function is defined, then it gets executed every time rc is about to print $prompt(1). 😌
  • status (no-export read-only) β€” the exit status of the last command. if the command exited with a numeric value, that number is the status. if the command died with a signal, the status is the name of that signal; if a core file was created, the string +core is appended. the value of $status for a pipeline is a list, with one entry, as above, for each process in the pipeline. for example, the command
ls | wc

usually sets $status to (0 0). 😭

  • tab (default) β€” contains the tab character (see Backquote substitution above).
  • version (default) β€” on startup, the first element of this list variable is initialized to a string which identifies this version of rc. the second element is initialized to a string which can be found by ident(1) and the what command of sccs(1). ⭐

πŸ¦‹ FUNCTIONS πŸ¦‹

bestie, rc functions are literally identical to rc scripts, except that they are stored in memory and are automatically exported into the environment. main character energy. πŸ’–

a shell function is declared as:

fn name { commands }

rc scans the definition until the close-brace, so the function can span more than one line. the function definition may be removed by typing

fn name

(one or more names may be specified. with an accompanying definition, all names receive the same definition. this is sometimes useful for assigning the same signal handler to many signals. without a definition, all named functions are deleted.) 🫢

when a function is executed, $* is set to the arguments to that function for the duration of the command. so a reasonable definition for l, a shorthand for ls(1), could be:

fn l { ls -FC $* }

but not

fn l { ls -FC } # WRONG

like. do not do that one. πŸ’€


πŸ”₯ INTERRUPTS AND SIGNALS πŸ”₯

rc recognizes a number of signals, and allows the user to define shell functions which act as signal handlers. rc by default traps SIGINT when it is in interactive mode. SIGQUIT and SIGTERM are ignored, unless rc has been invoked with the -d0 flag. however, user-defined signal handlers may be written for these and all other signals. πŸ’…

the way to define a signal handler is to write a function by the name of the signal in lower case. thus:

fn sighup { echo hangup; rm /tmp/rc$pid.*; exit }

in addition to Unix signals, rc recognizes the artificial signal SIGEXIT which occurs as rc is about to exit. ✨

in order to remove a signal handler's definition, remove it as though it were a regular function. for example:

fn sigint

returns the handler of SIGINT to the default value. in order to ignore a signal, set the signal handler's value to {}. thus:

fn sigint {}

causes SIGINT to be ignored by the shell. only signals that are being ignored are passed on to programs run by rc; signal functions are not exported. 🧚

on System V-based Unix systems, rc will not allow you to trap SIGCLD. πŸ’€

πŸ‘‘ BUILTIN COMMANDS πŸ‘‘

okay so builtins run in the context of the shell, but literally every other way they behave exactly like normal commands, fr fr. and lowkey, !, ~ and @ aren't strictly speaking builtin commands, but bestie, they can usually be used as such. πŸ’…

  • . [-i] file [arg ...] β€” Reads file as input to rc and executes its contents. With a -i0 flag, input is interactive. So from within a shell script,
. -i /dev/tty0

does the β€œright thing”. ✨

  • break β€” Breaks from the innermost for0 or while,0 as in C. It is an error to invoke break outside of a loop. (Note that there is no break keyword between commands in switch0 statements, unlike C.) 🫢
  • builtin command [arg ...] β€” Executes the command ignoring any function definition of the same name. This command is present to allow functions with the same names as builtins to use the underlying builtin or binary. For example:
fn ls { builtin ls -FC $* }0

is a reasonable way to pass a default set of arguments to ls(1),0 whereas

fn ls { ls -FC $* } # WRONG0

is a non-terminating recursion, which will cause rc0 to exhaust its stack space and (eventually) terminate if it is executed.

🚨 bestie. that second one is marked # WRONG0 for a REASON. it will gobble up your stack space and then it's over for you. do not.
  • cd [directory] β€” Changes the current directory to directory. The variable $cdpath0 is searched for possible locations of directory, analogous to the searching of $path0 for executable files. With no argument, cd changes the current directory to $home.0 🌸
  • continue β€” Continues the innermost for0 or while0 loop, as in C. It is an error to invoke continue outside of a loop.
  • echo [-n] [--] [arg ...] β€” Prints its arguments to standard output, terminated by a newline. Arguments are separated by spaces. If the first argument is -n0 no final newline is printed. If the first argument is --,0 then all other arguments are echoed literally. This is used for echoing a literal -n.0
  • eval [list] β€” Concatenates the elements of list with spaces and feeds the resulting string to rc for re-scanning. This is the only time input is rescanned in rc. πŸ”₯
  • exec [arg ...] β€” Replaces rc with the given command. If the exec contains only redirections, then these redirections apply to the current shell and the shell does not exit. For example,
exec >[2] err.out0

places further output to standard error in the file err.out.

  • exit [status] β€” Cause the current shell to exit with the given exit status. If no argument is given, the current value of $status0 is used.
  • flag f [ + | - ] β€” Test, set (+), or reset (-) command-line flag f. For example, a script that requires β€œexit if command fails” semantics can say
flag e +0

Some flags cannot be set or reset using flag, but they can still be tested. These are c, d, l, o, p, and s. As a special case, flag i0 operates on rc's internal interactive flag, which may have been set by -i0 on the command line, or if standard input was a terminal; there is no flag I.0

  • limit [-h] [resource [value]] β€” Similar to the csh(1) limit builtin, this command operates upon the BSD-style resource limits of a process. The -h0 flag displays/alters the hard limits. The resources which can be shown or altered are cputime, filesize, datasize, stacksize, coredumpsize, memoryuse, and, where supported, descriptors, memoryuse, memoryrss, maxproc, memorylocked, and filelocks. For example:
limit coredumpsize 00

disables core dumps. To set a soft limit equal to the hard limit:

limit `{limit -h datasize}0
  • newpgrp β€” Puts rc into a new process group. This builtin is useful for making rc behave like a job-control shell in a hostile environment. One example is the NeXT Terminal program, which implicitly assumes that each shell it forks will put itself into a new process group. 🧚
  • return [n] β€” Returns from the current function, with status n, where n is a valid exit status, or a list of them. Thus it is legal to have
return (sigpipe 1 2 3)0

(This is commonly used to allow a function to return with the exit status of a previously executed pipeline of commands.) If n is omitted, then $status0 is left unchanged. It is an error to invoke return when not inside a function.

  • shift [n] β€” Deletes n elements from the beginning of $*0 and shifts the other elements down by n. n defaults to 1.
  • umask [mask] β€” Sets the current umask (see umask(2)) to the octal mask. If no argument is present, the current mask value is printed.
  • wait [pid] β€” Waits for process with the specified pid, which must have been started by rc, to exit. If no pid is specified, rc waits for all its child processes to exit. πŸ’œ
  • whatis [-b] [-f] [-p] [-s] [-v] [--] [name ...] β€” Prints a definition of the named objects. For builtins, builtin0 foo is printed; for functions, including signal handlers, their definitions are printed; for executable files, path names are printed; and for variables, their values are printed. The flags restrict output to builtins, functions, executable programs, signal handlers, and variables, respectively. If no names are specified, rc lists all objects of that type. (This is not permitted for -p.)0 Without arguments, whatis0 is equivalent to whatis -fv,0 and prints the values of all shell variables and functions.

Note that whatis output is suitable for input to rc; by saving the output of whatis in a file, it should be possible to recreate the state of rc by sourcing this file with a .0 command. Another note: whatis -s > file0 cannot be used to store the state of rc's signal handlers in a file, because builtins with redirections are run in a subshell, and rc always restores signal handlers to their default value after a fork().0 😭

Since whatis uses getopt(3) to parse its arguments, you can use the special argument --0 to terminate its flags. This allows you to use names beginning with a dash, such as the history(1) commands. For example,

whatis -- -p0

🌈 EXAMPLES 🌈

The shift builtin only shifts $*.0 This function can shift any variable (except $_lshift).0 🌟

fn lshift { _lshift=$* *=$$1 { shift $_lshift(2); $_lshift(1)=$* } }0

With this definition in place,

walrus = (shoes ships sealing-wax cabbages kings)0
lshift walrus 30
whatis walrus0

prints

walrus=(cabbages kings)0

The $^var0 operator flattens a list by separating each element with a space. This function allows the separator to be an arbitrary string. πŸŽ€

fn lflat {0
  lflat=$*; *=$$10
  while () {0
    echo -n $1; shift0
    ~ $#* 0 && break0
    echo -n $lflat(2)0
  }0
}0

With this definition in place,

hops=(uunet mcvax ukc tlg)0
lflat hops !0

prints (with no final newline)

uunet!mcvax!ukc!tlg0

πŸ’– EXIT STATUS πŸ’–

The exit status of rc is normally the same as that of the last command executed. If the last command was a pipeline, rc exits 00 if every command in the pipeline did; otherwise it exits 1.0

rc can be made to exit with a particular status using the exit builtin. periodt. πŸ’…


✨ LINE EDITING ✨

rc is typically built against a line editing library. On GNU/Linux systems this will usually be the GNU readline library. On *BSD systems it is more likely to be the BSD editline library. Please consult the appropriate library documentation for details of how to use and configure line editing. πŸ¦‹

πŸŽ€ Tilde Expansion πŸŽ€

Since rc does not support tilde expansion (converting ~foo0 to the home directory of user foo),0 it is sometimes suggested by users as a possible enhancement. The authors and maintainers of rc have a proud history of resisting such feature requests. So it is worth noting here that GNU readline can expand tildes. Add this line to the file .inputrc0 in your home directory.

set expand-tilde on0

and then use the key sequence M-~0 to perform tilde expansion on the current word. See the readline documentation for further details. πŸ’œ

🌈 GRAMMAR 🌈

okay bestie, this is the moment where rc shows you its whole entire skeleton πŸ’€ it's the yacc grammar, with all the semantic actions βœ‚οΈ edited out, so it's just the raw shape of the language. Iconic. Terrifying. Beautiful. All three.

%term ANDAND BACKBACK BANG CASE COUNT DUP ELSE END FLAT FN FOR IF IN
%term OROR PIPE REDIR SUB SUBSHELL SWITCH TWIDDLE WHILE WORD HUH

%left '^' '='
%left WHILE ')' ELSE
%left ANDAND OROR '\n'
%left BANG SUBSHELL
%left PIPE
%right '$'
%left SUB

%start rc

%%

rc: line end
     | error end

end: END /* EOF */ | '\n'

cmdsa: cmd ';' | cmd '&'

line: cmd | cmdsa line

body: cmd | cmdsan body

cmdsan: cmdsa | cmd '\n'

brace: '{' body '}'

paren: '(' body ')'

assign: first optcaret '=' optcaret word

epilog: /* empty */ | redir epilog

redir: DUP | REDIR word

case: CASE words ';' | CASE words '\n'

cbody: cmd | case cbody | cmdsan cbody

iftail: cmd    %prec ELSE
     | brace ELSE optnl cmd

cmd  : /* empty */  %prec WHILE
     | simple
     | brace epilog
     | IF paren optnl iftail
     | FOR '(' word IN words ')' optnl cmd
     | FOR '(' word ')' optnl cmd
     | WHILE paren optnl cmd
     | SWITCH '(' word ')' optnl '{' cbody '}'
     | TWIDDLE optcaret word words
     | cmd ANDAND optnl cmd
     | cmd OROR optnl cmd
     | cmd PIPE optnl cmd
     | redir cmd    %prec BANG
     | assign cmd   %prec BANG
     | BANG optcaret cmd
     | SUBSHELL optcaret cmd
     | FN words brace
     | FN words

optcaret: /* empty */ %prec '^' | '^'

simple: first | first args

args: arg | args arg

arg: word | redir

first: comword | first '^' sword

sword: comword | keyword

word: sword | word '^' sword

comword: '$' sword
     | '$' sword SUB words ')'
     | COUNT sword
     | FLAT sword
     | '`' sword
     | '`' brace
     | BACKBACK word     brace | BACKBACK word sword
     | '(' words ')'
     | REDIR brace
     | WORD

keyword: FOR | IN | WHILE | IF | SWITCH
     | FN | ELSE | CASE | TWIDDLE | BANG | SUBSHELL | '='

words: /* empty */ | words word

optnl: /* empty */ | optnl '\n'

no cap, staring at a grammar is a whole vibe check. iykyk ✨


πŸ“ FILES πŸ“

the spots where rc keeps its little treasures 🫢

  • $HOME/.rcrc,0
  • /tmp/rc*,0
  • /dev/null0

πŸ’– CREDITS πŸ’–

rc was written by Byron Rakitzis, with valuable help from Paul Haahr, Hugh Redelmeier and David Sanderson. The design of this shell was copied from the rc that Tom Duff wrote at Bell Labs. king behaviour honestly πŸ‘‘ giving credit where credit is due, periodt.


πŸ’€ BUGS πŸ’€

buckle up bestie, this is the "we're being honest with each other" section πŸ™ˆ

  • There is a compile-time limit on the number of ;0 separated commands in a line: usually 500. This is sometimes a problem for automatically generated scripts: substituting the newline character for ;0 avoids the limit.
  • On modern systems that support /dev/fd0 or /proc/self/fd,0, <{foo}0 style redirection is implemented that way. However, on older systems it is implemented with named pipes. Allegedly, it is sometimes possible to foil rc into removing the FIFO it places in /tmp0 prematurely, or it is even possible to cause rc to hang. (The current maintainer has never seen this, but then he doesn't use systems which lack /dev/fd0 any more. If anybody can reproduce this problem, please let the maintainer know.)
  • The echo command does not need to be a builtin. It is one for reasons of performance and portability (of rc scripts).
  • There should be a way to avoid exporting a variable.
  • Extra parentheses around a ~0 expression or a !0 expression are a syntax error. Thus, this code is illegal.
while ((~ $1 -*) && (! ~ $1 --)) { ...0

The redundant inner parentheses must be omitted.

  • Variable subscripting cannot be used in here documents.
  • The limit0 builtin silently ignores extra arguments.
  • Backquote substitution never produces empty strings β€” multiple consecutive occurrences of the separator are treated the same as a single occurrence.
ifs=! { x = `{echo -n a!!b}; whatis x }0
x=(a b) # NOT x=(a '' b)0

Bug reports should be mailed to <toby@paccrat.org>.0

ok so that last one is literally the official channel, not me being cute 🌸 pls use it and not my DMs.

πŸ¦‹ INCOMPATIBILITIES πŸ¦‹

this is the ✨ lore drop ✨ β€” a whole list of features which distinguish this incarnation of rc from the one described in the Bell Labs manual pages:

  • The Tenth Edition rc does not have the else keyword. Instead, if is optionally followed by an if not clause which is executed if the preceding if test does not succeed.
  • Backquotes are slightly different in Tenth Edition rc: a backquote must always be followed by a left-brace. This restriction is not present for single-word commands in this rc.
  • For .0 file, the Tenth Edition rc searches $path0 for file. This rc does not, since it is not considered useful.
  • The list flattening operator, $^foo,0, is spelt $"foo0 in those versions of the Bell Labs rc which have it.
  • The following are all new with this version of rc: The -n0 flag, here strings (they facilitate exporting of functions with here documents into the environment), the return and break keywords, the echo builtin, the bqstatus0 and version0 variables, the prompt0 function, support for GNU readline and other line editing libraries. This rc also sets $00 to the name of a function being executed/file being sourced.

πŸ‘€ SEE ALSO πŸ‘€

go read more, bestie, it's giving scholar πŸ“šβœ¨


and that's a wrap on the whole entire page, no crumbs left πŸŽ€ this version is stamped 2015-05-13, and yeah the source is literally just the RC(1) manual page itself β€” that's the page we've been screaming about this whole time πŸ’… slay, go write some scripts, ily 🫢

πŸ“¦ where this page comes from