📄 ash.1
字号:
jobid [ job ]
Print the process id's of the processes in the job. If the job argument
is omitted, use the current job.
jobs
This command lists out all the background processes which are children of
the current shell process.
pwd
Print the current directory. The builtin command may differ from the
program of the same name because the builtin command remembers what the
current directory is rather than recomputing it each time. This makes it
faster. However, if the current directory is renamed, the builtin
version of pwd will continue to print the old name for the directory.
7BSD March 7, 1991 11
SH(1) Minix Programmer's Manual SH(1)
read [ -p prompt ] [ -e ] variable...
The prompt is printed if the -p option is specified and the standard
input is a terminal. Then a line is read from the standard input. The
trailing newline is deleted from the line and the line is split as
described in the section on word splitting above, and the pieces are
assigned to the variables in order. If there are more pieces than
variables, the remaining pieces (along with the characters in IFS that
separated them) are assigned to the last variable. If there are more
variables than pieces, the remaining variables are assigned the null
string.
The -e option causes any backslashes in the input to be treated
specially. If a backslash is followed by a newline, the backslash and
the newline will be deleted. If a backslash is followed by any other
character, the backslash will be deleted and the following character will
be treated as though it were not in IFS, even if it is.
readonly name...
The specified names are marked as read only, so that they cannot be
subsequently modified or unset. Ash allows the value of a variable to be
set at the same time it is marked read only by writing
readonly name=value
With no arguments the readonly command lists the names of all read only
variables.
set [ { -options | +options | -- } ] arg...
The set command performs three different functions.
With no arguments, it lists the values of all shell variables.
If options are given, it sets the specified option flags, or clears them
if the option flags are introduced with a + rather than a -. Only the
first argument to set can contain options. The possible options are:
-e Causes the shell to exit when a command terminates with a nonzero
exit status, except when the exit status of the command is explicitly
tested. The exit status of a command is considered to be explicitly
tested if the command is used to control an if, elif, while, or
until; or if the command is the left hand operand of an ``&&'' or
``||'' operator.
-f Turn off file name generation.
-I 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 a row.
-i Make the shell interactive. This causes the shell to prompt for
7BSD March 7, 1991 12
SH(1) Minix Programmer's Manual SH(1)
input, to trap interrupts, to ignore quit and terminate signals, and
to return to the main command loop rather than exiting on error.
-j Turns on Berkeley job control, on systems that support it. When the
shell starts up, the -j is set by default if the -i flag is set.
-n Causes the shell to read commands but not execute them. (This is
marginally useful for checking the syntax of scripts.)
-s If this flag is set when the shell starts up, the shell reads
commands from its standard input. The shell doesn't examine the
value of this flag any other time.
-x If this flag is set, the shell will print out each command before
executing it.
-z If this flag is set, the file name generation process may generate
zero files. If it is not set, then a pattern which does not match
any files will be replaced by a quoted version of the pattern.
The third use of the set command is to set the values of the shell's
positional parameters to the specified args. To change the positional
parameters without changing any options, use ``--'' as the first argument
to set. If no args are present, the set command will leave the value of
the positional parameters unchanged, so to set the positional parameters
to set of values that may be empty, execute the command
shift $#
first to clear out the old values of the positional parameters.
setvar variable value
Assigns value to variable. (In general it is better to write
variable=value rather than using setvar. Setvar is intended to be used
in functions that assign values to variables whose names are passed as
parameters.)
shift [ n ]
Shift the positional parameters n times. A shift sets the value of $1 to
the value of $2, the value of $2 to the value of $3, and so on,
decreasing the value of $# by one. If there are zero positional
parameters, shifting doesn't do anything.
trap [ action ] signal...
Cause the shell to parse and execute action when any of the specified
signals are received. The signals are specified by signal number.
Action may be null or omitted; the former causes the specified signal to
be ignored and the latter causes 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
7BSD March 7, 1991 13
SH(1) Minix Programmer's Manual SH(1)
that were ignored on entry to the shell.
umask [ mask ]
Set the value of umask (see umask(2)) to the specified octal value. If
the argument is omitted, the umask value is printed.
unset name...
The specified variables and functions are unset and unexported. If a
given name corresponds to both a variable and a function, both the
variable and the function are unset.
wait [ job ]
Wait for the specified job to complete and return the exit status of the
last process in the job. If the argument is omitted, wait for all jobs
to complete and the return an exit status of zero.
EXAMPLES
The following function redefines the cd command:
cd() {
if command cd "$@"
then if test -f .enter
then . .enter
else return 0
fi
fi
}
This function causes the file ``.enter'' to be read when you enter a
directory, if it exists. The command command is used to access the real
cd command. The ``return 0'' ensures that the function will return an
exit status of zero if it successfully changes to a directory that does
not contain a ``.enter'' file. Redefining existing commands is not
always a good idea, but this example shows that you can do it if you want
to.
The suspend function distributed with ash looks like
# 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
}
This turns off job control and then sends a stop signal to the current
process group, which suspends the shell. (When job control is turned on,
7BSD March 7, 1991 14
SH(1) Minix Programmer's Manual SH(1)
the shell ignores the TSTP signal.) Job control will be turned back on
when the function returns because ``-'' is local to the function. As an
example of what not to do, consider an earlier version of suspend:
suspend() {
suspend_flag=$-
set +j
kill -TSTP 0
set -$suspend_flag
}
There are two problems with this. First, suspend_flag is a global
variable rather than a local one, which will cause problems in the
(unlikely) circumstance that the user is using that variable for some
other purpose. Second, consider what happens if shell received an
interrupt signal after it executes the first set command but before it
executes the second one. The interrupt signal will abort the shell
function, so that the second set command will never be executed and job
control will be left off. The first version of suspend avoids this
problem by turning job control off only in a local copy of the shell
options. The local copy of the shell options is discarded when the
function is terminated, no matter how it is terminated.
HINTS
Shell variables can be used to provide abbreviations for things which you
type frequently. For example, I set
export h=$HOME
in my .profile so that I can type the name of my home directory simply by
typing ``$h''.
When writing shell procedures, try not to make assumptions about what is
imported from the environment. Explicitly unset or initialize all
variables, rather than assuming they will be unset. If you use cd, it is
a good idea to unset CDPATH.
People sometimes use ``<&-'' or ``>&-'' to provide no input to a command
or to discard the output of a command. A better way to do this is to
redirect the input or output of the command to /dev/null.
Word splitting and file name generation are performed by default, and you
have to explicitly use double quotes to suppress it. This is backwards,
but you can learn to live with it. Just get in the habit of writing
double quotes around variable and command substitutions, and omit them
only when you really want word splitting and file name generation. If
you want word splitting but not file name generation, use the -f option.
7BSD March 7, 1991 15
SH(1) Minix Programmer's Manual SH(1)
AUTHORS
Kenneth Almquist
SEE ALSO
echo(1), expr(1), line(1), pwd(1), true(1).
BUGS
When command substitution occurs inside a here document, the commands
inside the here document are run with their standard input closed. For
example, the following will not word because the standard input of the
line command will be closed when the command is run:
cat <<-!
Line 1: $(line)
Line 2: $(line)
!
Unsetting a function which is currently being executed may cause strange
behavior.
The shell syntax allows a here document to be terminated by an end of
file as well as by a line containing the terminator word which follows
the ``<<''. What this means is that if you mistype the terminator line,
the shell will silently swallow up the rest of your shell script and
stick it in the here document.
7BSD March 7, 1991 16
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -