- 论坛徽章:
- 0
|
原帖由 dearvoid 于 2008-8-14 18:14 发表 ![]()
在你脚本的开始位置加上一句 set -e
长见识了。谢谢楼上。
顺便查了一下,把所有的set 选项都列出来给大家参考
-a allexport
Flag variables for export when assignments are made to them.
-b notify
Enable asynchronous notification of background job completion.
(UNIMPLEMENTED)
-C noclobber
Do not overwrite existing files with ``>''.
-E emacs
Enable the built-in emacs(1) command line editor (disables the -V
option if it has been set).
-e errexit
Exit immediately if any untested command fails in non-interactive
mode. The exit status of a command is considered to be explic-
itly tested if the command is part of the list used to control an
if, elif, while, or until; if the command is the left hand oper-
and of an ``&&'' or ``||'' operator; or if the command is a pipe-
line preceded by the ! operator. If a shell function is executed
and its exit status is explicitly tested, all commands of the
function are considered to be tested as well.
-f noglob
Disable pathname expansion.
-I ignoreeof
Ignore EOF's from input when in interactive mode.
-i interactive
Force the shell to behave interactively.
-m monitor
Turn on job control (set automatically when interactive).
-n noexec
If not interactive, read commands but do not execute them. This
is useful for checking the syntax of shell scripts.
-P physical
Change the default for the cd and pwd commands from -L (logical
directory layout) to -P (physical directory layout).
-p privileged
Turn on privileged mode. This mode is enabled on startup if
either the effective user or group id is not equal to the real
user or group id. Turning this mode off sets the effective user
and group ids to the real user and group ids. When this mode is
enabled for interactive shells, the file /etc/suid_profile is
sourced instead of ~/.profile after /etc/profile is sourced, and
the contents of the ENV variable are ignored.
-s stdin
Read commands from standard input (set automatically if no file
arguments are present). This option has no effect when set after
the shell has already started running (i.e., when set with the
set command).
-T trapsasync
When waiting for a child, execute traps immediately. If this
option is not set, traps are executed after the child exits, as
specified in IEEE Std 1003.2 (``POSIX.2''). This nonstandard
option is useful for putting guarding shells around children that
block signals. The surrounding shell may kill the child or it
may just return control to the tty and leave the child alone,
like this:
sh -T -c "trap 'exit 1' 2 ; some-blocking-program"
-u nounset
Write a message to standard error when attempting to expand a
variable that is not set, and if the shell is not interactive,
exit immediately.
-V vi Enable the built-in vi(1) command line editor (disables -E if it
has been set).
-v verbose
The shell writes its input to standard error as it is read. Use-
ful for debugging.
-x xtrace
Write each command (preceded by the value of the PS4 variable) to
standard error before it is executed. Useful for debugging. |
|