linnux
exec执行 COMMAND,用指定程序替换此 shell
exec 作用
- 执行命令
exec在当前 shell 进程内用指定命令原地替换进程映像(execve 系统调用),PID 不变、不创建新进程;替换后原 shell 已不存在,命令结束后不会返回原 shell- 如
exec rbash
- 设置重定向
- 如
exec >> /tmp/x.log 2>&1将标准错误 2 重定向到标准输出 1,并输出到/tmp/x.log,如果在 shell 文件中,该命令行下面所有的输出都会被输出到/tmp/x.log中
- 如
help
$ exec --help
exec: exec [-cl] [-a name] [command [argument ...]] [redirection ...]
Replace the shell with the given command.
Execute COMMAND, replacing this shell with the specified program.
ARGUMENTS become the arguments to COMMAND. If COMMAND is not specified,
any redirections take effect in the current shell.
Options:
-a name pass NAME as the zeroth argument to COMMAND
-c execute COMMAND with an empty environment
-l place a dash in the zeroth argument to COMMAND
If the command cannot be executed, a non-interactive shell exits, unless
the shell option `execfail' is set.
Exit Status:
Returns success unless COMMAND is not found or a redirection error occurs.最近更新
最新评论