📄 ash.1
字号:
.\" Copyright (c) 1991 The Regents of the University of California..\" All rights reserved..\".\" This code is derived from software contributed to Berkeley by.\" Kenneth Almquist..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\" may be used to endorse or promote products derived from this software.\" without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" @(#)sh.1 5.1 (Berkeley) 3/7/91.\".TH SH 1 "March 7, 1991".UC 7.de h \" subheading.sp.ti -0.3i.B "\\$1".PP...de d \" begin display.sp.in +4.nf...de e \" end display.in -4.fi.sp...de c \" command, etc..br.HP 3\fB\\$1\fR.br...de b \" begin builtin command.HP 3.B \\$1...SH NAMEash, command, getopts, hash, jobs, local, return, setvar, unset \- a shell.SH SYNOPSIS.B ash[.B -efIijnsxz] [.B +efIijnsxz] [.B -c.I command] [.I arg] ....SH COPYRIGHTCopyright 1989 by Kenneth Almquist..SH DESCRIPTION.I Ashis a version of.I shwith features similar to those of the System V shell.This manual page lists all the features of.I ashbut concentrates on the ones not in other shells..h "Invocation"If the.B -coptions is given, then the shell executes the specified shell command.The.B -sflag cause the shell to read commands from the standard input (afterexecuting any command specified with the.B -coption.If neither the.B -sor.B -coptions are set, then the first.I argis taken as the name of a file to read commands from.If this is impossible because there are no arguments followingthe options, then.I ashwill set the.B -sflag and will read commands from the standard input..PPThe shell sets the initial value of the positional parameters from the.IR arg sremaining after any.I argused as the name of a file of commands is deleted..PPThe flags (other than.BR -c )are set by preceding them with ``-'' and cleared by preceding themwith ``+''; see the.I setbuiltin command for a list of flags.If no value is specified for the.B -iflag, the.B -sflag is set, and the standard input and output of the shellare connected to terminals, then the.B -iflag will be set.If no value is specified for the.B -jflag, then the.B -jflag will be set if the.B -iflag is set..PPWhen the shell is invoked with the.B -coption, it is good practice to include the.I -iflag if the command was entered interactively by a user.For compatibility with the System V shell, the.I -ioption should come after the.B -coption..PPIf the first character of argument zero to the shell is ``-'',the shell is assumed to be a login shell, and the files.B /etc/profileand.B .profileare read if they exist.If the environment variable SHINIT is set on entry to the shell,the commands in SHINIT are normally parsed and executed. SHINIT isnot examined if the shell is a login shell, or if it the shell is running ashell procedure. (A shell is considered to be running a shellprocedure if neither the.B -snor the.B -coptions are set.).h "Control Structures"A.I listis a sequence of zero or more commands separated by newlines,semicolons, or ampersands, and optionally terminated by one of thesethree characters. (This differs from the System V shell, whichrequires a list to contain at least one command in most cases.) Thecommands in a list are executed in the order they are written.If command is followed by an ampersand, the shell starts the commandand immediately proceed onto the next command; otherwise it waitsfor the command to terminate before proceeding to the next one..PP``&&'' and ``||'' are binary operators.``&&'' executes the first command, and then executes the second commandiff the exit status of the first command is zero. ``||'' is similar,but executes the second command iff the exit status of the first commandis nonzero. ``&&'' and ``||'' both have the same priority..PPThe ``|'' operator is a binary operator which feeds the standard outputof the first command into the standard input of the second command.The exit status of the ``|'' operator is the exit status of the secondcommand. ``|'' has a higher priority than ``||'' or ``&&''..PPAn.I ifcommand looks like.d\fBif\fR list\fBthen\fR list.ti -\w'[ 'u[ \fBelif\fR list \fBthen\fR list ] ....ti -\w'[ 'u[ \fBelse\fR list ]\fBfi\fR.e.PPA.I whilecommand looks like.d\fBwhile\fR list\fBdo\fR list\fBdone\fR.eThe two lists are executed repeatedly while the exit status of the firstlist is zero. The.I untilcommand is similar, but has the word.B untilin place of.B while repeats until the exit status of the first listis zero..PPThe.I forcommand looks like.d\fBfor\fR variable \fBin\fR word...\fBdo\fR list\fBdone\fR.eThe words are expanded, and then the list is executed repeatedly withthe variable set to each word in turn..B doand.B donemay be replaced with``{'' and ``}''..PPThe.I breakand.I continuecommands look like.d\fBbreak\fR [ num ]\fBcontinue\fR [ num ].e.I Breakterminates the.I numinnermost.I foror.I whileloops..I Continuecontinues with the next iteration of the.IRnum'thinnermost loop.These are implemented as builtin commands..PPThe.I casecommand looks like.d\fBcase\fR word \fBin\fRpattern\fB)\fR list \fB;;\fR\&...\fBesac\fR.eThe pattern can actually be one or more patterns (see.I Patternsbelow), separated by ``|'' characters..PPCommands may be grouped by writing either.d\fB(\fRlist\fB)\fR.eor.d\fB{\fR list; \fB}\fR.eThe first of these executes the commands in a subshell..PPA function definition looks like.dname \fB( )\fR command.eA function definition is an executable statement; when executed it installsa function named.B nameand returns an exit status of zero.The command is normally a list enclosed between ``{'' and ``}''..PPVariables may be declared to be local to a function by using a.I localcommand. This should appear as the first staement of a function,and looks like.d\fBlocal\fR [ variable | \fB-\fR ] ....e.I Localis implemented as a builtin command..PPWhen a variable is made local, it inherits the initial value andexported and readonly flags from the variable with the same name in thesurrounding scope, if there is one. Otherwise, the variable isinitially unset..I Ashuses dynamic scoping, so that if you make the variable.B xlocal to function.IR f ,which then calls function.IR g ,references to the variable.B xmade inside.I gwill refer to the variable.B xdeclared inside.IR f ,not to the global variable named.BR x ..PPThe only special parameter than can be made local is ``\fB-\fR''.Making ``\fB-\fR'' local any shell options that are changed via the.I setcommand inside the function to be restored to their original valueswhen the function returns..PPThe.I returncommand looks like.d\fBreturn\fR [ exitstatus ].eIt terminates the currently executing function..I Returnis implemented as a builtin command..h "Simple Commands"A simple command is a sequence of words. The execution of a simplecommand proceeds as follows. First, the leading words of the form``name=value'' are stripped off and assigned to the environment ofthe command. Second, the words are expanded. Third, the firstremaining word is taken as the command name that command is located.Fourth, any redirections are performed. Fifth, the command isexecuted. We look at these operations in reverse order..PPThe execution of the command varies with the type of command.There are three types of commands: shell functions, builtin commands,and normal programs..PPWhen a shell function is executed, all of the shell positional parameters(except $0, which remains unchanged) are set to the parameters to the shellfunction. The variables which are explicitly placed in the environmentof the command (by placing assignments to them before the function name)are made local to the function and are set to values given.Then the command given in the function definition is executed.The positional parameters are restored to their original values whenthe command completes..PPShell builtins are executed internally to the shell, without spawninga new process..PPWhen a normal program is executed, the shell runs the program, passingthe parameters and the environment to the program. If the program isa shell procedure, the shell will interpret the program in a subshell.The shell will reinitialize itself in this case, so that the effectwill be as if a new shell had been invoked to handle the shell procedure,except that the location of commands located in the parent shell willbe remembered by the child. If the program is a file beginning with``#!'', the remainder of the first line specifies an interpreter forthe program. The shell (or the operating system, under Berkeley UNIX)will run the interpreter in this case. The arguments to the interpreter
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -