📄 ksh.1
字号:
or.B typeset \-xcommands..PPThe environment for any.I simple-commandor functionmay be augmented by prefixing it with one or more parameter assignments.A parameter assignment argument is a word of the form.IR identifier=value .Thus:.RS.PP\s-1TERM\s+1=450 \|cmd \|args and.br(export \|\s-1TERM\s+1; \|\s-1TERM\s+1=450; \|cmd \|args).RE.PPare equivalent (as far as the above execution of.I cmdis concerned)..PPIf the.B \-kflag is set,.I allparameter assignment arguments are placed in the environment,even if they occur after the command name.The followingfirst prints.B "a=b c"and then.BR c:.PP.RS.nfecho \|a=b \|cset \|\-kecho \|a=b \|c.fi.REThis feature is intended for use with scripts writtenfor early versions of the shell and its use in new scriptsis strongly discouraged.It is likely to disappear someday..SS Functions..PPThe.B functionreserved word, described in the.I Commandssection above,is used to define shell functions.Shell functions are read in and stored internally.Alias names are resolved when the function is read.Functions are executed like commands with the argumentspassed as positional parameters.(See.I Executionbelow)..PPFunctions execute in the same process as the caller andshare all filesand present working directory with thecaller.Traps caught by the caller are reset to their default actioninside the function.A trap condition that is not caught or ignored by thefunction causes the function to terminate and the conditionto be passed on to the caller.A trap on.SM.B EXITset inside a functionis executed after the function completes in the environmentof the caller.Ordinarily,variables are shared between the calling programand the function.However,the.B typesetspecial command used within a functiondefines local variables whose scope includesthe current function andall functions it calls..PPThe special command.B returnis used to returnfrom function calls.Errors within functions return control to the caller..PPFunction identifierscan be listed with the.B \-for.B +foption of the.B typesetspecial command.The text of functions will alsobe listed with.BR \-f .Function can be undefined with the.B \-foption of the.B unsetspecial command..PPOrdinarily,functions are unset when the shell executes a shell script.The.B \-xfoption of the.B typesetcommand allows a function to be exportedto scripts that are executed without a separateinvocation of the shell.Functions that need to be defined across separateinvocations of the shell should be specified in the.SMENVfile with the .B \-xfoption of.B typeset.SS Jobs..PPIf the.B monitoroption of the.B setcommand is turned on,an interactive shell associates a \fIjob\fR with each pipeline.It keepsa table of current jobs, printed by the.B jobscommand, and assigns them small integer numbers.When a job is started asynchronously with.BR & ,the shell prints a line which lookslike:.PP.DT [1] 1234.PPindicating that the job which was started asynchronously was job number1 and had one (top-level) process, whose process id was 1234..PPThis paragraph and the next require features that arenot in all versions of the UNIX operating system and may not apply.If you are running a job and wish to do something else you may hit the key\fB^Z\fR (control-Z) which sends a STOP signal to the current job.The shell will then normally indicate that the job has been `Stopped',and print another prompt.You can then manipulate the state of this job,putting it in the background with the.B bgcommand, or run some othercommands and then eventually bring the job back into the foreground withthe foreground command.BR fg .A \fB^Z\fR takes effect immediately andis like an interrupt in that pending output and unread input are discardedwhen it is typed..PPA job being run in the background will stop if it tries to readfrom the terminal.Background jobs are normally allowed to produce output,but this can be disabled by giving the command ``stty tostop''.If you set thistty option, then background jobs will stop when they try to produceoutput like they do when they try to read input..PPThere are several ways to refer to jobs in the shell.A job can be referred to by the process id of any process of the jobor by one of the following:.PD 0.TP.BI % numberThe job with the given number..TP.BI % stringAny job whose command line begins with.IR string ..TP.BI %? stringAny job whose command line contains.IR string ..TP.BI %%Current job..TP.BI %+Equivalent to.BR %% ..TP.BI %\-Previous job..PD.PPThis shell learns immediately whenever a process changes state.It normally informs you whenever a job becomes blocked so thatno further progress is possible, but only just before it printsa prompt.This is done so that it does not otherwise disturb your work..PPWhen the monitor mode is on, each background job that completestriggers any trap set for.BR CHLD ..PPWhen you try to leave the shell while jobs are running or stopped, you willbe warned that `You have stopped(running) jobs.'You may use the.B jobscommand to see what they are.If you do this or immediately try toexit again, the shell will not warn you a second time, and the stoppedjobs will be terminated..SS Signals.The \s-1INT\s+1 and \s-1QUIT\s+1 signals for an invokedcommand are ignored if the command is followed by.B &and job.B monitoroption is not active.Otherwise, signals have the valuesinherited by the shell from its parent(but see alsothe.B trapcommand below)..SS Execution.Each time a command is executed, the above substitutionsare carried out.If the command name matches oneof the.I "Special Commands"listed below,it is executed within thecurrent shell process.Next, the command name is checked to see ifit matches one of the user defined functions.If it does,the positional parameters are savedand then reset to the arguments of the.I functioncall.When the.I functioncompletes or issues a.BR return ,the positional parameter list is restoredand any trap set on.SM.B EXITwithin the function is executed.The value of a.I functionis the value of the last command executed.A function is also executed in thecurrent shell process.If a command name is not a.I "special command"or a user defined.IR function ,a process is created andan attempt is made to execute the command via.IR exec (2)..PPThe shell parameter.SM PATHdefines the search path forthe directory containing the command.Alternative directory names are separated bya colon.RB ( : ).The default path is.B /bin:/usr/bin:(specifying.BR /bin ,.BR /usr/bin ,and the current directoryin that order).The current directory can be specified bytwo or more adjacent colons, or by a colonat the beginning or end of the path list.If the command name contains a \fB/\fP then the search pathis not used.Otherwise, each directory in the path issearched for an executable file.If the file has execute permission but is not adirectory or an.B a.outfile,it is assumed to be a file containing shell commands.A sub-shell is spawned to read it.All non-exported aliases,functions,and named parameters are removed in this case.If the shell commandfile doesn't have read permission,or if the.I setuidand/or.I setgidbits are set on the file,then the shell executes an agent whose job it is toset up the permissions and execute the shell with theshell command file passed down as an open file.A parenthesized command is executed ina sub-shell without removing non-exported quantities..SS Command Re-entry.The text of the last.SMHISTSIZE(default 128)commands entered from a terminal deviceis saved in a.I historyfile.The file.B \s-1$HOME\s+1/.sh_historyis used if the.SMHISTFILEvariable is not setor is not writable.A shell can access the commands ofall.I interactiveshells which use the same named.SM.BR HISTFILE .The special command.B fcis used to list oredit a portion of this file.The portion of the file to be edited or listed can be selected bynumber or by giving the first character orcharacters of the command.A single command or range of commands can be specified.If you do not specify an editor program asan argument to.B fcthen the value of the parameter.SM.B FCEDITis used.If.SM.B FCEDITis not defined then.B /bin/edis used.The edited command(s) is printed and re-executed uponleaving the editor.The editor name.B \-is used to skip the editing phase andto re-execute the command.In this case a substitution parameter of the form\fIold\fP\fB=\fP\fInew\fPcan be used to modify the command before execution.For example, if.B ris aliased to.B \(fmfc \-e \-\(fmthen typing`\fBr bad=good c\fP'will re-execute the most recent command which starts with the letter.BR c ,replacing the first occurrence of the string.B badwith the string.BR good ..SS In-line Editing OptionsNormally, each command line entered from a terminal device is simplytyped followed by a new-line (`RETURN' or `LINE\ FEED').If either the.BR emacs ,.BR gmacs ,or.B vioption is active, the user can edit the command line.To be in either of these edit modes.B setthe correspondingoption.An editing option is automatically selected each time the.SM.B VISUALor.SM.B EDITORvariable is assigned a value ending in either of theseoption names..PPThe editing features require that the user's terminalaccept `RETURN' as carriage return without line feedand that a space (`\ ') must overwrite the current character onthe screen.ADM terminal users should set the "space - advance"switch to `space'.Hewlett-Packard series 2621 terminal users should set the straps to`bcGHxZ\ etX'..PPThe editing modes implement a concept where the user is looking through awindow at the current line.The window width is the value of.SM.B COLUMNSif it is defined, otherwise 80.If the line is longer than the window width minus two, a mark isdisplayed at the end of the window to notify the user.As the cursor moves and reaches the window boundaries the window will becentered about the cursor.The mark is a.BR > " (<" ,.BR * )if the line extends on theright (left, both) side(s) of the window..PPThe search commands in each edit mode provide access to the history file.Only strings are matched, not patterns, although a leading.B ^in the string restricts the matchto begin at the first character in the line..SS Emacs Editing ModeThis mode is entered by enabling either the.I emacsor.I gmacsoption.The only difference between these two modes is the waythey handle.BR ^T .To edit, the usermoves the cursor to the point needing correction andthen inserts or deletes characters or words as needed.All the editing commands are control characters or escapesequences.The notation for control characters is caret (.B ^) followedby the character.For example,.B ^Fis the notation for control.BR F .This is entered by depressing `f' while holding down the`CTRL' (control) key.The `SHIFT' key is.I notdepressed.(The notation.B ^?indicates the DEL (delete) key.).PPThe notation for escape sequences is.B M-followed by acharacter.For example,.B M-f(pronounced Meta f)is entered by depressing ESC(ascii.BR 033 )followed by `f'..RB ( M-Fwould be the notation for ESC followed by `SHIFT' (capital) `F'.).PPAll edit commandsoperate from any place on the line(not just at the beginning).Neither the "RETURN" nor the "LINE FEED" key isentered after edit commands except when noted..PP.PD 0.TP 10.BI ^FMove cursor forward (right) one character..PP.TP 10.BI M-fMove cursor forward one word.(The emacs editor's idea of a word is a string of charactersconsisting of only letters, digits and underscores.).PP.TP 10.BI ^BMove cursor backward (left) one character..PP.TP 10.BI M-bMove cursor backward one word..PP.TP 10.BI ^AMove cursor to start of line..PP.TP 10.BI ^EMove cursor to end of line..PP.TP 10.BI ^] charMove cursor forward to character.I charon current line..PP.TP 10.BI M-^] charMove cursor back to character.I charon current line..PP.TP 10.BI ^X^XInterchange the cursor and mark..PP.TP 10.I erase(User defined erase character as definedby the.IR stty (1)command, usually.B ^Hor.BR # .)Delete previous character..PP.TP 10.BI ^DDelete current character..PP.TP 10.BI M-dDelete current word..PP.TP 10.BI M-^H(Meta-backspace) Delete previous word..PP.TP 10.BI M-hDelete previous word..PP.TP 10.BI M-^?(Meta-DEL) Delete previous word (if your interrupt character is.B ^?(DEL, the default) then this command will not work)..PP.TP 10.BI ^TTranspose current character with next character in.I emacsmode.Transpose two previous characters in.I gmacsmode..PP.TP 10.BI ^CCapitalize current character..PP.TP 10.BI M-cCapitalize current word..PP.TP 10.BI M-lChange the current word to lower case..PP.TP 10.BI ^KDelete from the cursor to the end of the line.If preceded by a numerical parameter whose value is less than thecurrent cursor position, then delete from given positionup to the cursor.If preceded by a numerical parameter whose value is greater than thecurrent cursor position, then delete from cursor up togiven cursor position..PP.TP 10.BI ^WKill from the cursor to the mark..PP.TP 10.BI M-pPush the region from the cursor to the mark on the stack..PP.TP 10.I kill(User defined kill character as definedby the stty command, usually.B ^Gor.BR @ .)Kill the entire current line.If two.I killcharacters are entered in succession, allkill characters from then on cause a line feed(useful when using paper terminals)..PP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -