table of contents
rc(1) | General Commands Manual | rc(1) |
NAME¶
rc - run commands
SYNOPSIS¶
rc [-c script] [command] [args...]
DESCRIPTION¶
rc runs the rc shell script at command, with the provided args. If no command is provided, commands are read from the standard input. If the standard input is a terminal, rc starts an interactive shell session.
OPTIONS¶
-c script
EXTENDED DESCRIPTION¶
rc runs shell scripts using a shell command language with various features for scripting command execution. Lines beginning with # are comments and are ignored; # at any unquoted location also causes the remainder of that line to be ignored.
If the shell is started in interactive mode, the file ~/.config/rc/rcstart is sourced on startup (or $XDG_CONFIG_HOME/rc/rcstart, if set).
SIMPLE COMMANDS¶
Simple commands are formed by forming a list of strings separated by spaces. Double or single quotes may be used to form arguments with spaces or special characters. Commands are terminated by a newline, and '\' may be placed before a newline to cause a command to continue on the subsequent line.
echo hello world echo "hello world" echo hello \ world # continuation line
Quoted strings which immediately follow each other, without whitespace characters between, are concatenated. Strings with double quotes are subject to variable expansion, i.e. variable references using the $ operators are expanded by the shell. Unquoted characters are interpreted as arguments if they do not include any of the following special characters:
Escape sequences within quoted strings (either single or double quote) are as follows:
Sequence | Character | Name |
\0 | NUL | null |
\a | BEL | bell |
\f | FF | form feed |
\n | LF | line feed |
\r | CR | carriage return |
\t | HT | horizontal tab |
\v | VT | vertical tab |
\\ | \ | backslash |
\' | ' | single quote |
\" | " | double quote |
GLOBBING¶
Unquoted strings, when used as arguments to a command, are subject to "globbing". If * appears in an unquoted string, it will be treated as a globbing pattern and expanded to a list of matching files.
The globbing pattern syntax is:
- ?: matches any single character
- *: matches any string, including empty string
- [...]: matches a set of or range of characters
- [!...]: inverse of [...]
- \: escapes the following character
- all other characters match themselves
VARIABLES¶
To define a variable, use the = operator and provide a value; to reference it, use $:
x="hello world" echo $x # prints "hello world"
rc supports two types of variables: strings and lists of strings. A list is defined by grouping a list of values, separated by spaces, in parenthesis.
x=(hello world) echo $x # echo "hello" "world"
The use of a list variable in a command line expands to a series of arguments, rather than a single argument. Conversely, a string variable always expands to a single argument. Thus, it is not necessary to quote variables.
On shell start-up, all environment variables are imported into shell variables and marked as exported.
VARIABLE OPERATORS
$#var
x=hello echo $#x # 5 x=(one two three) echo $#x # 3
The $# operator may be used on undefined variables without raising an error; it returns 0 in this case.
$"var $'var
x=(one two three) echo $x # echo "one" "two" "three" echo $"x # echo "one two three" echo $'x # echo "onetwothree"
$var(n)
$var(x-y)
SPECIAL VARIABLES
The following variables are defined by the shell automatically:
Name | Value |
$* | List of arguments |
$0, $1, $2, ... | String representing the numbered argument* |
$pid | Process ID of the shell itself |
$status | Exit status of last command |
* Note that $0 is the command name and $1 is the first argument
ARGUMENT EXPANSION¶
When an argument or value appears unquoted, it is subject to argument expansion. In addition to the operators described by VARIABLE OPERATORS above, the following operators are supported:
`{ script... }
`"string"{ script... }
The second form, with the included "string", splits the standard output of script into a list using the characters in "string" as delimiters.
@{ script }
@"string"{ script }
<{ script }
>{ script }
PIPELINES¶
Any command may be piped into a another with the | operator.
command | command
command |[fd] command
command |[fd=fd] command
If only one file descriptor is provided, the second command's standard input is used.
command && command
command || command
REDIRECTIONS¶
command > file
command >> file
command < file
command >[fd] file
May also be used with >> and <.
command >[fd=]
SUB-SCRIPTS¶
{ script }
IF STATEMENTS¶
if ( command ) command
if ( command ) command else command
LOOPS¶
for ( arg ) command
for ( arg in arguments... )
command
while ( command ) command
FUNCTIONS¶
fn name command
fn name ( variable list... )
command
If a variable list is provided (separated by spaces), each argument will be assigned to a local variable with the given name. Any arguments not provided will leave the corresponding variable unset. $* is unaffected, and may (for instance) be used to access additional arguments beyond the list of named arguments.
fn print_args { for (arg) { echo $arg } } print_args hello world fn write_file(path contents) { echo $contents >$path } write_file example.txt "hello world"
BUILT-IN COMMANDS¶
The following commands are built into the shell.
. name args...
~ subject patterns...
The pattern syntax is as follows:
- ?: matches any single character
- *: matches any string, including empty string
- [...]: matches a set of or range of characters
- [!...]: inverse of [...]
- \: escapes the following character
- all other characters match themselves
Globbing is disabled while processing the arguments to a ~ command, so you needn't quote patterns explicitly.
cd directory
break
continue
eval script
exit status
echo args...
read
Example usage:
shift n
unset names...
AUTHORS¶
Maintained by Drew Devault <sir@cmpwn.com>.
2025-01-15 |