📄 ash.1
字号:
Move the specified job or the current job to the foreground.This command is only available on systems with Bekeley job control..b getopts.I optstring.I var.brThe System V.I getoptscommand..b hash.B -rv.IR command ....brThe shell maintains a hash table which remembers the locations ofcommands. With no arguments whatsoever, the hash command printsout the contents of this table. Entries which have not been lookedat since the last.I cdcommand are marked with an asterisk; it is possible for these entriesto be invalid..spWith arguments, the hash command removes the specified commands fromthe hash table (unless they are functions) and then locates them.With the.B -voption,.I hashprints the locations of the commands as it finds them.The.B -roption causes the.I hashcommand to delete all the entries in the hash table except forfunctions..b jobid[.I job].brPrint the process id's of the processes in the job. If the job argumentis omitted, use the current job..b jobs.brThis command lists out all the background processes which are childrenof the current shell process..b pwd.brPrint the current directory. The builtin command may differ from theprogram of the same name because the builtin command remembers whatthe current directory is rather than recomputing it each time. Thismakes it faster. However, if the current directory is renamed, thebuiltin version of pwd will continue to print the old name for thedirectory..b read[.B -p.I prompt][.B -e].IR variable ....brThe prompt is printed if the.B -poption is specified and the standard input is a terminal. Then aline is read from the standard input. The trailing newline is deletedfrom the line and the line is split as describedin the section on word splitting above, and the pieces are assigned tothe variables in order. If there are more pieces than variables, theremaining pieces (along with the characters in IFS that separated them)are assigned to the last variable. If there are more variables thanpieces, the remaining variables are assigned the null string..spThe.B -eoption causes any backslashes in the input to be treated specially.If a backslash is followed by a newline, the backslash and the newlinewill be deleted. If a backslash is followed by any other character,the backslash will be deleted and the following character will be treatedas though it were not in IFS, even if it is..b readonly.IR name ....brThe specified names are marked as read only, so that they cannot besubsequently modified or unset..I Ashallows the value of a variable to be set at the same time it is markedread only by writing.d\fBreadonly\fR name=value.eWith no arguments the readonly command lists the names of allread only variables..b set[{.BI - options|.BI + options|.B --}].IR arg ....brThe.I setcommand performs three different functions..spWith no arguments, it lists the values of all shell variables..spIf options are given, it sets the specified option flags, or clearsthem if the option flags are introduced with a.B +rather than a.BR - .Only the first argument to.I setcan contain options.The possible options are:.sp.ta 0.4i.in +0.4i.ti -0.4i\fB-e\fR Causes the shell to exit when a command terminates witha nonzero exit status, except when the exit status of the command isexplicitly tested. The exit status of a command is considered to beexplicitly tested if the command is used to control an.IR if ,.IR elif ,.IR while ,or.IR until ;or if the command is the left hand operand of an ``&&'' or ``||''operator..sp.ti -0.4i\fB-f\fR Turn off file name generation..sp.ti -0.4i\fB-I\fR Cause the shell to ignore end of file conditions.(This doesn't apply when the shell a script sourced using the ``.''command.) The shell will in fact exit if it gets 50 eof's in arow..sp.ti -0.4i\fB-i\fR Make the shell interactive. This causes the shell toprompt for input, to trap interrupts, to ignore quit and terminate signals,and to return to the main command loop rather than exiting on error..sp.ti -0.4i\fB-j\fR Turns on Berkeley job control, on systems that support it.When the shell starts up, the.B -jis set by default if the.B -iflag is set..sp.ti -0.4i\fB-n\fR Causes the shell to read commands but not execute them.(This is marginally useful for checking the syntax of scripts.).sp.ti -0.4i\fB-s\fR If this flag is set when the shell starts up, the shellreads commands from its standard input. The shell doesn't examine thevalue of this flag any other time..sp.ti -0.4i\fB-x\fR If this flag is set, the shell will print out eachcommand before executing it..sp.ti -0.4i\fB-z\fR If this flag is set, the file name generation processmay generate zero files. If it is not set, then a pattern which doesnot match any files will be replaced by a quoted version of the pattern..in -0.4i.spThe third use of the set command is to set the values of the shell'spositional parameters to the specified.IR args .To change the positional parameters without changing any options,use ``\fB--\fR'' as the first argument to.IR set .If no args are present, the set command will leave the value of thepositional parameters unchanged, so to set the positional parametersto set of values that may be empty, execute the command.dshift $#.efirst to clear out the old values of the positional parameters..b setvar.I variable.I value.brAssigns.I valueto.IR variable .(In general it is better to write.I variable=valuerather than using.IR setvar ..I Setvaris intended to be used in functions that assign values to variables whosenames are passed as parameters.).b shift[.I n].brShift the positional parameters.I ntimes.A shift sets the value of $1 to the value of $2, the value of $2 tothe value of $3, and so on, decreasing the value of $# by one.If there are zero positional parameters, shifting doesn't do anything..b trap[.I action].IR signal ....brCause the shell to parse and execute.I actionwhen any of the specified signals are received.The signals are specified by signal number..I Actionmay be null or omitted;the former causes the specified signal to be ignored and the lattercauses the default action to be taken.When the shell forks off a subshell, it resets trapped (but not ignored)signals to the default action.The trap command has no effect on signals that were ignored on entryto the shell..b umask[.I mask].brSet the value of umask (see.IR umask (2))to the specified octal value. If the argument is omitted, the umaskvalue is printed..b unset.IR name ....brThe specified variables and functions are unset and unexported.If a given name corresponds to both a variable and a function, both thevariable and the function are unset..b wait[.I job].brWait for the specified job to complete and return the exit status of thelast process in the job. If the argument is omitted, wait for all jobsto complete and the return an exit status of zero..SH EXAMPLESThe following function redefines the \fIcd\fR command:.dcd() { if command cd "$@" then if test -f .enter then . .enter else return 0 fi fi}.eThis function causes the file ``.enter'' to be read when you enter adirectory, if it exists. The \fIcommand\fR command is used to access thereal \fIcd\fR command. The ``return 0'' ensures that the function willreturn an exit status of zero if it successfully changes to a directorythat does not contain a ``.enter'' file. Redefining existing commandsis not always a good idea, but this example shows that you can do it ifyou want to..PPThe suspend function distributed with.I ashlooks like.d# Copyright (C) 1989 by Kenneth Almquist. All rights reserved.# This file is part of ash, which is distributed under the terms# specified by the Ash General Public License.suspend() { local - set +j kill -TSTP 0}.eThis turns off job control and then sends a stop signal to the currentprocess group, which suspends the shell. (When job control is turnedon, the shell ignores the TSTP signal.) Job control will be turned backon when the function returns because ``-'' is local to the function.As an example of what \fInot\fR to do, consider an earlier version of\fIsuspend\fR:.dsuspend() { suspend_flag=$- set +j kill -TSTP 0 set -$suspend_flag}.eThere are two problems with this. First, \fBsuspend_flag\fR is a globalvariable rather than a local one, which will cause problems in the(unlikely) circumstance that the user is using that variable for someother purpose. Second, consider what happens if shell received an interruptsignal after it executes the first \fIset\fR command but before it executesthe second one. The interrupt signal will abort the shell function, sothat the second \fIset\fR command will never be executed and job controlwill be left off. The first version of \fIsuspend\fR avoids this problemby turning job control off only in a local copy of the shell options. Thelocal copy of the shell options is discarded when the function is terminated,no matter how it is terminated..SH HINTSShell variables can be used to provide abbreviations for things whichyou type frequently. For example, I set.br.\" \h'1i'export h=$HOME.\" Cawf can't do \h'1i'.in +1iexport h=$HOME.in -1i.brin my .profile so that I can type the name of my home directory simplyby typing ``$h''..PPWhen writing shell procedures, try not to make assumptions about what isimported from the environment. Explicitly unset or initialize all variables,rather than assuming they will be unset. If you use cd, it is a good ideato unset CDPATH..PPPeople sometimes use ``<&-'' or ``>&-'' to provide no input to a commandor to discard the output of a command. A better way to do this isto redirect the input or output of the command to.BR /dev/null ..PPWord splitting and file name generation are performed by default,and you have to explicitly use double quotes to suppress it. This isbackwards, but you can learn to live with it. Just get in the habit ofwriting double quotes around variable and command substitutions, andomit them only when you really want word splitting and file name generation.If you want word splitting but not file name generation, use the.B -foption..SH AUTHORSKenneth Almquist.SH "SEE ALSO"echo(1), expr(1), line(1), pwd(1), true(1)..SH BUGSWhen command substitution occurs inside a here document, the commands insidethe here document are run with their standard input closed. For example,the following will not word because the standard input of the.I linecommand will be closed when the command is run:.dcat <<-!Line 1: $(line)Line 2: $(line)!.e.PPUnsetting a function which is currently being executed may cause strangebehavior..PPThe shell syntax allows a here document to be terminated by an end of fileas well as by a line containing the terminator word which follows the ``<<''.What this means is that if you mistype the terminator line, the shellwill silently swallow up the rest of your shell script and stick itin the here document.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -