⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sh.1

📁 早期freebsd实现
💻 1
📖 第 1 页 / 共 3 页
字号:
.\" Copyright (c) 1991, 1993.\"	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	8.4 (Berkeley) 4/18/94.\".na.TH SH 1.SH NAMEsh \- command interpreter (shell).SH SYNOPSISsh [-/+aCefnuvxIimsVEb] [-/+o longname] [arg ...].SH DESCRIPTION.LPSh is the standard command interpreter for the system.The current version of sh is in the process of being changed toconform with the POSIX 1003.2 and 1003.2a specifications forthe shell.  This version has many features which make it appearsimilar in some respects to the Korn shell, but it is not a Kornshell clone (run GNU's bash if you want that).  Only featuresdesignated by POSIX, plus a few Berkeley extensions, are beingincorporated into this shell.  We expect POSIX conformance by thetime 4.4 BSD is released.This man page is not intended to be a tutorial or a completespecification of the shell..sp 2.B Overview.sp.LPThe shell is a command that reads lines fromeither a file or the terminal, interprets them, andgenerally executes other commands. It is the program that is runningwhen a user logs into the system (although a user can selecta different shell with the chsh(1) command).The shellimplements a language that has flow control constructs,a macro facility that provides a variety of features inaddition to data storage, along with built in history and lineediting capabilities.  It incorporates many features toaid interactive use and has the advantage that the interpretativelanguage is common to both interactive and non-interactiveuse (shell scripts).  That is, commands can be typed directlyto the running shell or can be put into a file and the filecan be executed directly by the shell..sp 2.B Invocation.sp.LPIf no args are present and if the standard input of the shellis connected to a terminal (or if the -i flag is set), the shellis considered an interactive shell.  An interactive shellgenerally prompts before each command and handles programmingand command errors differently (as described below).When first starting, the shell inspects argument 0, andif it begins with a dash '-', the shell is also considereda login shell.  This is normally done automatically by the systemwhen the user first logs in. A login shell first reads commandsfrom the files /etc/profile and .profile if they exist.If the environment variable ENV is set on entry to a shell,or is set in the .profile of a login shell, the shell next readscommands from the file named in ENV.  Therefore, a user shouldplace commands that are to be executed only at login time inthe .profile file, and commands that are executed for everyshell inside the ENV file.  To set the ENV variable to somefile, place the following line in your .profile of your homedirectory.nf		ENV=$HOME/.shinit; export ENV.fisubstituting for ``.shinit'' any filename you wish.Since the ENV file is read forevery invocation of the shell, including shell scripts andnon-interactive shells, the following paradigm is usefulfor restricting commands in the ENV file to interactive invocations.Place commands within the ``case'' and ``esac'' below (thesecommands are described later):.nf	case $- in *i*)		# commands for interactive use only		...	esac.fiIf command line arguments besides the options have beenspecified, then the shell treats the first argument as thename of a file from which to read commands (a shell script), andthe remaining arguments are set as the positional parametersof the shell ($1, $2, etc).  Otherwise, the shell reads commandsfrom its standard input..sp 2.B Argument List Processing.sp.LPAll of the single letter options have a corresponding namethat can be used as an argument to the '-o' option. Theset -o name is provided next to the single letter option inthe description below.Specifying a dash ``-'' turns the option on, while using a plus ``+''disables the option.The following options can be set from the command line orwith the set(1) builtin (described later)..TP-a    allexportExport all variables assigned to.(UNIMPLEMENTED for 4.4alpha).TP-C    noclobberDon't overwrite existing files with ``>''.(UNIMPLEMENTED for 4.4alpha).TP-e    errexitIf not interactive, exit immediately if anyuntested command fails.The exit status of a command is considered to beexplicitly tested if the command is used to controlan if, elif, while, or until; or if the command is the lefthand operand of an ``&&'' or ``||'' operator..TP-f    noglobDisable pathname expansion..TP-n    noexecIf not interactive, read commands but do notexecute them.  This is useful for checking thesyntax of shell scripts..TP-u    nounsetWrite a message to standard error when attemptingto expand a variable that is not set, and if theshell is not interactive, exit immediately.(UNIMPLEMENTED for 4.4alpha).TP-v    verboseThe shell writes its input to standard erroras it is read.  Useful for debugging..TP-x    xtraceWrite each command to standard error (precededby a '+ ') before it is executed.  Useful fordebugging..TP-I    ignoreeofIgnore EOF's from input when interactive..TP-i    interactiveForce the shell to behave interactively..TP-m    monitorTurn on job control (set automatically wheninteractive)..TP-s    stdinRead commands from standard input (set automaticallyif no file arguments are present).  This option hasno effect when set after the shell has already startedrunning (i.e. with set(1))..TP-V    viEnable the builtin vi(1) command line editor (disables-E if it has been set)..TP-E    emacsEnable the builtin emacs(1) command line editor (disables-V if it has been set)..TP-b    notifyEnable asynchronous notification of background jobcompletion.(UNIMPLEMENTED for 4.4alpha).LP.sp 2.B Lexical Structure.sp.LPThe shell reads input in terms of lines from a file and breaksit up into words at whitespace (blanks and tabs), and atcertain sequences ofcharacters that are special to the shell called ``operators''.There are two types of operators: control operators andredirection operators (their meaning is discussed later).Following is a list of operators:.nf.spControl operators: &  &&  (  )  ;  ;; | || <newline>.spRedirection operator:  <  >  >|  <<  >>  <&  >&  <<-  <>.sp.fi.sp 2.B Quoting.sp.LPQuoting is used to remove the special meaning of certain charactersor words to the shell, such as operators, whitespace, orkeywords.  There are three types of quoting: matched single quotes,matched double quotes, and backslash..sp 2.B Backslash.sp.LPA backslash preserves the literal meaning of the followingcharacter, with the exception of <newline>.  A backslash precedinga <newline> is treated as a line continuation..sp 2.B Single Quotes.sp.LPEnclosing characters in single quotes preserves the literalmeaning of all the characters..sp 2.B Double Quotes.sp.LPEnclosing characters within double quotes preserves the literalmeaning of all characters except dollarsign ($), backquote (`),and backslash (\\).  The backslash inside double quotes ishistorically weird, and serves to quote only the followingcharacters: $  `  "  \\  <newline>.Otherwise it remains literal..sp 2.B Reserved Words.sp.LPReserved words are words that have special meaning to theshell and are recognized at the beginning of a line andafter a control operator.  The following are reserved words:.nf   !	elif	fi	while	case   else	for	then	{	}   do	done	until	if	esac.fiTheir meaning is discussed later..sp 2.B Aliases.sp.LPAn alias is a name and corresponding value set using the alias(1)builtin command.  Whenever a reserved word may occur (see above),and after checking for reserved words, the shellchecks the word to see if it matches an alias. If it does,it replaces it in the input stream with its value.  For example,if there is an alias called ``lf'' with the value ``ls -F'',then the input.nf   lf foobar <return>	would become   ls -F foobar <return>.fi.LPAliases provide a convenient way for naive users tocreate shorthands for commands without having to learn howto create functions with arguments.  They can also beused to create lexically obscure code.  This use is discouraged..sp 2.B Commands.sp.LPThe shell interprets the words it reads according to alanguage, the specification of which is outside the scopeof this man page (refer to the BNF in the POSIX 1003.2document).  Essentially though, a line is read and ifthe first word of the line (or after a control operator)is not a reserved word, then the shell has recognized asimple command.  Otherwise, a complex command or someother special construct may have been recognized..sp 2.B Simple Commands.sp.LPIf a simple command has been recognized, the shell performsthe following actions:.sp1) Leading words of the form ``name=value'' arestripped off and assigned to the environment ofthe simple command.  Redirection operators andtheir arguments (as described below) are strippedoff and saved for processing..sp2) The remaining words are expanded as described inthe section called ``Expansions'', and thefirst remaining word is considered the commandname and the command is located.  The remainingwords are considered the arguments of the command.If no command name resulted, then the ``name=value''variable assignments recognized in 1) affect thecurrent shell..sp3) Redirections are performed as described inthe next section..sp 2.B Redirections.sp.LPRedirections are used to change where a command reads its inputor sends its output.  In general, redirections open, close, orduplicate an existing reference to a file.  The overall formatused for redirection is:.nf		[n] redir-op file.fiwhere redir-op is one of the redirection operators mentionedpreviously.  Following is a list of the possible redirections.The [n] is an optional number, as in '3' (not '[3]'), thatrefers to a file descriptor..TP[n]> file	Redirect standard output (or n) to file..TP[n]>| file	Same, but override the -C option..TP[n]>> file	Append standard output (or n) to file..TP[n]< file	Redirect standard input (or n) from file..TP[n1]<&n2	Duplicate standard input (or n1) fromfile descriptor n2..TP[n]<&-		Close standard input (or n)..TP[n1]>&n2	Duplicate standard output (or n) fromn2..TP[n]>&-		Close standard output (or n)..TP[n]<> file	Open file for reading and writing onstandard input (or n)..LPThe following redirection is often called a ``here-document''..nf    [n]<< delimiter        here-doc-text...    delimiter.fiAll the text on successive lines up to the delimiter issaved away and made available to the command on standardinput, or file descriptor n if it is specified.  If the delimiteras specified on the initial line is quoted, then the here-doc-textis treated literally, otherwise the text is subjected toparameter expansion, command substitution, and arithmeticexpansion (as described in the section on ``Expansions''). Ifthe operator is ``<<-'' instead of ``<<'', then leading tabsin the here-doc-text are stripped..sp 2.B Search and Execution.sp.LPThere are three types of commands: shell functions, builtin commands, and normal programs -- and thecommand is searched for (by name) in that order.  Theyeach are executed in a different way..LPWhen a shell function is executed, all of the shell positional parameters (except $0, which remains unchanged) areset to the arguments of the shell function.The variables which are explicitly placed in the environment ofthe command (by placing assignments to them before thefunction name) are made local to the function and are setto the values given. Then the command given in the functiondefinition is executed.   The positional parameters arerestored to their original values when the command completes..LPShell builtins are executed internally to the shell, without spawning a new process..LPOtherwise, if the command name doesn't match a functionor builtin, the command is searched for as a normalprogram in the filesystem (as described in the next section).When a normal program is executed, the shell runs the program,passing the arguments and the environment to theprogram. If the program is a shell procedure, the shellwill interpret the program in a subshell.  The shell willreinitialize itself in this case, so that the effect willbe as if a new shell had been invoked to handle the shellprocedure, except that the location of commands located inthe parent shell will be remembered by the child..sp 2.B Path Search.sp.LPWhen locating a command, the shell first looks to see ifit has a shell function by that name.  Then it looks for abuiltin command by that name.Finally, it searches eachentry in PATH in turn for the command..LPThe value of the PATH variable should be a series ofentries separated by colons.  Each entry consists of a

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -