.TH SH 1.SH NAMEsh, builtin, exit, load, loaded, local, whatis, quote, run, set, unload, unquote \- command language.SH SYNOPSIS.B sh[.B -ilxvn][.B -c command][.I file[.I arg ...].SH DESCRIPTION.I Shis a programmable user level interface (a shell) for Inferno.It executes command lines read from a terminal or a file or, with the.B -cflag, from.IR sh 'sargument list. It can also be used to give programmable functionalityto Limbo modules (see.IR sh "" "" (2))..SS Command LinesA command line is a sequence of commands, separated by ampersands or semicolons.RB ( &or.BR ; ),terminated by a newline.The commands are executed in sequencefrom left to right..I Shdoes not wait for a command followed by.B &to finish executing before startingthe following command.Whenever a command followed by.B &is executed, its process id is assigned to the.I shvariable.BR $apid .Whenever a command.I notfollowed by.B &exits or is terminated, the.I shvariable.B $statusgets the process's wait message (see.IR prog (3));it will be the null string if the command was successful..PPA number-sign.RB ( # )and any following characters up to (but not including) the next newlineare ignored, except in quotation marks..SS Simple CommandsA simple command is a sequence of arguments interspersed with I/O redirections.If the first argument is the name of a.I shbuiltin or it is a braced command block (see.IR "Compound Commands",below), it is executed by.IR sh .If the first character of the name is a brace.RB ( { ),the shell tries to parse it and execute it as a braced command block;if the parsing fails, an exception is raised.Otherwise.I shlooks for an external program to execute..PPIf the name ends in.BR .dis ,.I shlooks for a Dis module of that name; otherwiseit tries first to find a Dis module ofthat name with.B .disappended and failing that, it looks foran executable file of the same name, which shouldbe a readable, executable script file.If the name does not start with a slash.RB ( / )or dot-slash.RB ( ./ ),then the name is first looked for relative to.BR /dis ,and then relative to the current directory.A Dis module will be executed only if itimplements the.B Commandinterface (see.IR sh (1));a script file will be executed only if itstarts with the characters.RB `` #! ''followed by the name of a file executableunder the rules above. In this case thecommand will be executed with any following arguments mentionedin the.B #!header, followed by the path of the script file,followed by any arguments originally given to the command..PPFor example, to execute the simple command.BR "ls" ,.I shwill look for one of the following things, in order,stopping the search when one is found:.RS.IP 1)a built-in command named.RB `` ls ''..IP 2)a Dis module named.RB `` /dis/ls.dis '',.IP 3)an executable script file named.RB `` /dis/ls '',.IP 4)a Dis module named.RB `` ./ls.dis '',.IP 5)an executable script file named.RB `` ./ls ''..RE.SS Arguments and VariablesA number of constructions may be used where.I sh'ssyntax requires an argument to appear.In many cases a construction'svalue will be a list of arguments rather than a single string..PPThe simplest kind of argument is the unquoted word:a sequence of one or more characters none of which is a blank, tab,newline, or any of the following:.EX # ; & | ^ $ ` ' { } ( ) < > " =.EEAn unquoted word that contains any of the characters.B *.B ?.B [is a pattern for matching against file names.The character.B *matches any sequence of characters,.B ?matches any single character, and.BI [ class ]matches any character in the.IR class .If the first character of.I classis.BR ^ ,the class is complemented. (As this characteris special to the shell, it may only be included in a patternif this character is quoted, as long as the leading.B [is not quoted).The.I classmay also contain pairs of characters separated by.BR - ,standing for all characters lexically between the two.The character.B /must appear explicitly in a pattern.A pattern is replaced by a list of arguments, one for each path name matched,except that a pattern matching no names is not replaced by the empty list,but rather stands for itself.Pattern matching is done after all otheroperations.Thus,.EX x=/tmp; echo $x^/*.b.EEmatches.BR /tmp/*.b ,rather than matching.B "/*.band then prefixing.BR /tmp ..PPA quoted word is a sequence of characters surrounded by single quotes.RB ( ' ).A single quote is represented in a quoted word by a pair of quotes.RB ( '' )..PP.ne 3Each of the following is an argument..PD 0.HP.BI ( arguments ).brThe value of a sequence of arguments enclosed in parentheses isa list comprising the members of each element of the sequence.Argument lists have no recursive structure, although their syntax maysuggest it.The following are entirely equivalent:.EX echo hi there everybody ((echo) (hi there) everybody) echo (hi there everybody ).EENewlines within parentheses count as simple white space;they do not terminate the command. This can be useful to givesome more freedom of layout to commands that take severalcommands as arguments, for instance several of the commandsdefined in.IR sh-std (1)..HP.BI $ argument.brThe.I argumentafter the.B $is the name of a variable whose value is substituted.Multiple levelsof indirection are possible.Variable valuesare lists of strings.If.I argumentis a number.IR n ,the value is the.IR n thelement of.BR $* ,unless.B $*doesn't have.I nelements, in which case the value is empty.Assignments to variables are described under.I "Assignment" ,below..HP.BI $# argument.brThe value is the number of elements in the named variable.A variablenever assigned a value has zero elements..HP\f5$"\fP\fIargument\fP.brThe value is a single string containing the components of the named variableseparated by spaces. A variable with zero elements yields the empty string..HP.BI `{ command }.HP.I\f5"{\fPcommand\f5}\fP.br.I Shexecutes the.I commandand reads its standard output. If backquote.RB ( ` )is used, it is split into a list of arguments,using characters in.B $ifsas separators.If.B $ifsis not otherwise set, its value is.BR "'\ \et\en'" .If doublequote (\f5"\fP)is used, no tokenization takes place..HP.IB argument ^ argument.brThe.B ^operator concatenates its two operands.If the two operandshave the same number of components, they are concatenated pairwise.If not,then one operand must have one component, and the other must be non-empty,and concatenation is distributive..HP.BI ${ command }.br.I Commandmust be a simple command with no redirections;its first wordmust be the name of a builtin substitution operator.The operator is invoked and its value substituted.See.IR "Built-in Commands" ,below, for more information on builtins..HP.BI <{ command }.HP.BI >{ command }.brThe.I commandis executed asynchronously with its standard output or standard inputconnected to a pipe.The value of the argument is the name of a filereferring to the other end of the pipe.This allows the construction ofnon-linear pipelines.For example, the following runs two commands.B oldand.B newand uses.B cmpto compare their outputs.EX cmp <{old} <{new}.EE.PD.SS Free CaretsIn most circumstances,.I shwill insert the.B ^operator automatically between words that are not separated by white space.Whenever one of.B $.B '.B `follows a quoted or unquoted word or an unquoted word follows a quoted wordwith no intervening blanks or tabs,a.B ^is inserted between the two.If an unquoted word immediately follows a.BR $ and contains a character other than an alphanumeric, underscore,or.BR * ,a.B ^is inserted before the first such character.Thus.IP.B limbo -$flags $stem.b.LPis equivalent to.IP.B limbo -^$flags $stem^.b.SS AssignmentA command of the form.IB name = valueor.IB name := valueassigns.I valueto the environment variable named.IR name ..I Valueis either a list of arguments or an assignment statement. Inthe latter case.I valueis taken from the value assigned in the assignment statement.If.B :=is used, the value is stored in the innermost local scope.A local scope is created every time a braced block is entered,and destroyed when the block is left. If.B =is used, the value is stored in the innermost scopethat contains any definition of.IR name ..PPA list of names can also be used in place of.IR name ,which causes each element of.I valuein turn to be assigned the respective variable name inthe list. The last variable in the list is assigned any elementsthat are left over. If there are more variable names thanelements in.IR value ,the remaining elements are assigned the null list.For instance, after the assignment:.EX (a b c) = one two three four five.EE.B $ais.BR one ,.B $bis.BR two ,and.B $ccontains the remaining three elements.BR "(three four five)" ..SS I/O RedirectionsThe sequence.BI > fileredirects the standard output file (file descriptor 1, normally theterminal) to the named.IR file ;.BI >> fileappends standard output to the file.The standard input file (file descriptor 0, also normally the terminal)may be redirected from a file by the sequence.BI < file \f1,or by the sequence.BI <> file \f1,which opens the file for writing as well as reading.Note that if.I fileis in fact a parsed braced block, the redirection will be treated aspipe to the given command - it is identical to the.B "<{}"operator mentioned above..PPRedirections may be applied to a file-descriptor other than standard inputor output by qualifying the redirection operatorwith a number in square brackets.For example, the diagnostic output (file descriptor 2)may be redirected by writing.BR "limbo junk.b >[2] junk" ..PPA file descriptor may be redirected to an already open descriptor by writing.BI >[ fd0 = fd1 ]or.BI <[ fd0 = fd1 ]\f1..I Fd1is a previously opened file descriptor and.I fd0becomes a new copy (in the sense of .IR sys-dup (2))of it..PPRedirections are executed from left to right.Therefore,.B limbo junk.b >/dev/null >[2=1]and.B limbo junk.b >[2=1] >/dev/nullhave different effects: the first puts standard output in.BR /dev/nulland then puts diagnostic output in the same place, where the seconddirects diagnostic output to the terminal and sends standard output to.BR /dev/null ..SS Compound CommandsA pair of commands separated by a pipe operator.RB ( | )is a command.The standard output of the left command is sent through a pipeto the standard input of the right command.The pipe operator may be decoratedto use different file descriptors..BI |[ fd ]connects the output end of the pipe to file descriptor.I fdrather than 1..BI |[ fd0 = fd1 ]connects output to.I fd1of the left command and input to.I fd0of the right command..PPA sequence of commands separated by.BR & ,.BR ; ,or newlinemay be grouped by surroundingthem with braces.RB ( {} ),elsewhere referred to as a.IR "braced block" .A braced block may be used anywhere that a simple wordis expected. If a simple command is found witha braced block as its first word, thevariable.B $*is set to any following arguments,.B $0is set to the block itself, and the commandsare executed in sequence. If a braced blockis passed as an argument, no execution takes place:the block is converted to a functionally equivalentstring, suitable for later re-interpretation by the shell.The null command .RB ( {} )has no effect and always gives a nil status. For instancethe following commands all produce the same result:.EX echo hello worldLines 1–500 of 980. Load more
.TH SH 1 .SH NAME sh, builtin, exit, load, loaded, local, whatis, quote, run, set, unload, unquote \- command language .SH SYNOPSIS .B sh [ .B -ilxvn ] [ .B -c command ] [ .I file [ .I arg ... ] .SH DESCRIPTION .I Sh is a programmable user level interface (a shell) for Inferno. It executes command lines read from a terminal or a file or, with the .B -c flag, from .IR sh 's argument list. It can also be used to give programmable functionality to Limbo modules (see .IR sh "" "" (2)). .SS Command Lines A command line is a sequence of commands, separated by ampersands or semicolons .RB ( & or .BR ; ), terminated by a newline. The commands are executed in sequence from left to right. .I Sh does not wait for a command followed by .B & to finish executing before starting the following command. Whenever a command followed by .B & is executed, its process id is assigned to the .I sh variable .BR $apid . Whenever a command .I not followed by .B & exits or is terminated, the .I sh variable .B $status gets the process's wait message (see .IR prog (3)); it will be the null string if the command was successful. .PP A number-sign .RB ( # ) and any following characters up to (but not including) the next newline are ignored, except in quotation marks. .SS Simple Commands A simple command is a sequence of arguments interspersed with I/O redirections. If the first argument is the name of a .I sh builtin or it is a braced command block (see .IR "Compound Commands", below), it is executed by .IR sh . If the first character of the name is a brace .RB ( { ), the shell tries to parse it and execute it as a braced command block; if the parsing fails, an exception is raised. Otherwise .I sh looks for an external program to execute. .PP If the name ends in .BR .dis , .I sh looks for a Dis module of that name; otherwise it tries first to find a Dis module of that name with .B .dis appended and failing that, it looks for an executable file of the same name, which should be a readable, executable script file. If the name does not start with a slash .RB ( / ) or dot-slash .RB ( ./ ), then the name is first looked for relative to .BR /dis , and then relative to the current directory. A Dis module will be executed only if it implements the .B Command interface (see .IR sh (1)); a script file will be executed only if it starts with the characters .RB `` #! '' followed by the name of a file executable under the rules above. In this case the command will be executed with any following arguments mentioned in the .B #! header, followed by the path of the script file, followed by any arguments originally given to the command. .PP For example, to execute the simple command .BR "ls" , .I sh will look for one of the following things, in order, stopping the search when one is found: .RS .IP 1) a built-in command named .RB `` ls ''. .IP 2) a Dis module named .RB `` /dis/ls.dis '', .IP 3) an executable script file named .RB `` /dis/ls '', .IP 4) a Dis module named .RB `` ./ls.dis '', .IP 5) an executable script file named .RB `` ./ls ''. .RE .SS Arguments and Variables A number of constructions may be used where .I sh's syntax requires an argument to appear. In many cases a construction's value will be a list of arguments rather than a single string. .PP The simplest kind of argument is the unquoted word: a sequence of one or more characters none of which is a blank, tab, newline, or any of the following: .EX # ; & | ^ $ ` ' { } ( ) < > " = .EE An unquoted word that contains any of the characters .B * .B ? .B [ is a pattern for matching against file names. The character .B * matches any sequence of characters, .B ? matches any single character, and .BI [ class ] matches any character in the .IR class . If the first character of .I class is .BR ^ , the class is complemented. (As this character is special to the shell, it may only be included in a pattern if this character is quoted, as long as the leading .B [ is not quoted). The .I class may also contain pairs of characters separated by .BR - , standing for all characters lexically between the two. The character .B / must appear explicitly in a pattern. A pattern is replaced by a list of arguments, one for each path name matched, except that a pattern matching no names is not replaced by the empty list, but rather stands for itself. Pattern matching is done after all other operations. Thus, .EX x=/tmp; echo $x^/*.b .EE matches .BR /tmp/*.b , rather than matching .B "/*.b and then prefixing .BR /tmp . .PP A quoted word is a sequence of characters surrounded by single quotes .RB ( ' ). A single quote is represented in a quoted word by a pair of quotes .RB ( '' ). .PP .ne 3 Each of the following is an argument. .PD 0 .HP .BI ( arguments ) .br The value of a sequence of arguments enclosed in parentheses is a list comprising the members of each element of the sequence. Argument lists have no recursive structure, although their syntax may suggest it. The following are entirely equivalent: .EX echo hi there everybody ((echo) (hi there) everybody) echo (hi there everybody ) .EE Newlines within parentheses count as simple white space; they do not terminate the command. This can be useful to give some more freedom of layout to commands that take several commands as arguments, for instance several of the commands defined in .IR sh-std (1). .HP .BI $ argument .br The .I argument after the .B $ is the name of a variable whose value is substituted. Multiple levels of indirection are possible. Variable values are lists of strings. If .I argument is a number .IR n , the value is the .IR n th element of .BR $* , unless .B $* doesn't have .I n elements, in which case the value is empty. Assignments to variables are described under .I "Assignment" , below. .HP .BI $# argument .br The value is the number of elements in the named variable. A variable never assigned a value has zero elements. .HP \f5$"\fP\fIargument\fP .br The value is a single string containing the components of the named variable separated by spaces. A variable with zero elements yields the empty string. .HP .BI `{ command } .HP .I \f5"{\fPcommand\f5}\fP .br .I Sh executes the .I command and reads its standard output. If backquote .RB ( ` ) is used, it is split into a list of arguments, using characters in .B $ifs as separators. If .B $ifs is not otherwise set, its value is .BR "'\ \et\en'" . If doublequote (\f5"\fP) is used, no tokenization takes place. .HP .IB argument ^ argument .br The .B ^ operator concatenates its two operands. If the two operands have the same number of components, they are concatenated pairwise. If not, then one operand must have one component, and the other must be non-empty, and concatenation is distributive. .HP .BI ${ command } .br .I Command must be a simple command with no redirections; its first word must be the name of a builtin substitution operator. The operator is invoked and its value substituted. See .IR "Built-in Commands" , below, for more information on builtins. .HP .BI <{ command } .HP .BI >{ command } .br The .I command is executed asynchronously with its standard output or standard input connected to a pipe. The value of the argument is the name of a file referring to the other end of the pipe. This allows the construction of non-linear pipelines. For example, the following runs two commands .B old and .B new and uses .B cmp to compare their outputs .EX cmp <{old} <{new} .EE .PD .SS Free Carets In most circumstances, .I sh will insert the .B ^ operator automatically between words that are not separated by white space. Whenever one of .B $ .B ' .B ` follows a quoted or unquoted word or an unquoted word follows a quoted word with no intervening blanks or tabs, a .B ^ is inserted between the two. If an unquoted word immediately follows a .BR $ and contains a character other than an alphanumeric, underscore, or .BR * , a .B ^ is inserted before the first such character. Thus .IP .B limbo -$flags $stem.b .LP is equivalent to .IP .B limbo -^$flags $stem^.b .SS Assignment A command of the form .IB name = value or .IB name := value assigns .I value to the environment variable named .IR name . .I Value is either a list of arguments or an assignment statement. In the latter case .I value is taken from the value assigned in the assignment statement. If .B := is used, the value is stored in the innermost local scope. A local scope is created every time a braced block is entered, and destroyed when the block is left. If .B = is used, the value is stored in the innermost scope that contains any definition of .IR name . .PP A list of names can also be used in place of .IR name , which causes each element of .I value in turn to be assigned the respective variable name in the list. The last variable in the list is assigned any elements that are left over. If there are more variable names than elements in .IR value , the remaining elements are assigned the null list. For instance, after the assignment: .EX (a b c) = one two three four five .EE .B $a is .BR one , .B $b is .BR two , and .B $c contains the remaining three elements .BR "(three four five)" . .SS I/O Redirections The sequence .BI > file redirects the standard output file (file descriptor 1, normally the terminal) to the named .IR file ; .BI >> file appends standard output to the file. The standard input file (file descriptor 0, also normally the terminal) may be redirected from a file by the sequence .BI < file \f1, or by the sequence .BI <> file \f1, which opens the file for writing as well as reading. Note that if .I file is in fact a parsed braced block, the redirection will be treated as pipe to the given command - it is identical to the .B "<{}" operator mentioned above. .PP Redirections may be applied to a file-descriptor other than standard input or output by qualifying the redirection operator with a number in square brackets. For example, the diagnostic output (file descriptor 2) may be redirected by writing .BR "limbo junk.b >[2] junk" . .PP A file descriptor may be redirected to an already open descriptor by writing .BI >[ fd0 = fd1 ] or .BI <[ fd0 = fd1 ]\f1. .I Fd1 is a previously opened file descriptor and .I fd0 becomes a new copy (in the sense of .IR sys-dup (2)) of it. .PP Redirections are executed from left to right. Therefore, .B limbo junk.b >/dev/null >[2=1] and .B limbo junk.b >[2=1] >/dev/null have different effects: the first puts standard output in .BR /dev/null and then puts diagnostic output in the same place, where the second directs diagnostic output to the terminal and sends standard output to .BR /dev/null . .SS Compound Commands A pair of commands separated by a pipe operator .RB ( | ) is a command. The standard output of the left command is sent through a pipe to the standard input of the right command. The pipe operator may be decorated to use different file descriptors. .BI |[ fd ] connects the output end of the pipe to file descriptor .I fd rather than 1. .BI |[ fd0 = fd1 ] connects output to .I fd1 of the left command and input to .I fd0 of the right command. .PP A sequence of commands separated by .BR & , .BR ; , or newline may be grouped by surrounding them with braces .RB ( {} ), elsewhere referred to as a .IR "braced block" . A braced block may be used anywhere that a simple word is expected. If a simple command is found with a braced block as its first word, the variable .B $* is set to any following arguments, .B $0 is set to the block itself, and the commands are executed in sequence. If a braced block is passed as an argument, no execution takes place: the block is converted to a functionally equivalent string, suitable for later re-interpretation by the shell. The null command .RB ( {} ) has no effect and always gives a nil status. For instance the following commands all produce the same result: .EX echo hello world