
bash linux命令
Linux bash provides different commands for daily usage. exec
command is mainly used to run commands in a bash environment. We can also provide parameters to this command.
Linux bash提供了日常使用的不同命令。 exec
命令主要用于在bash环境中运行命令。 我们还可以为该命令提供参数。
句法 (Syntax)
Syntax of exec
command is like below.
exec
命令的语法如下。
exec OPTIONS COMMAND ARGUMENTS
直接运行程序或脚本 (Run Program or Script Directly)
Without using exec we can run programs and scripts too. But we should make these executable. We will use chmod u+x
command which makes given program or script executable for the owner.
不使用exec,我们也可以运行程序和脚本。 但是我们应该使它们可执行。 我们将使用chmod u+x
命令,使所有者的给定程序或脚本可执行。
$ chown u+x myscript.sh
and than we can run it directly without needing exec
command like below.
而且我们可以直接运行它而不需要如下所示的exec
命令。
$ ./myscript.sh
运行命令 (Run Command)
We can simply run a command by providing the COMMAND. Provided command will run without creating a new process. In this example we will run ls
command. After command execution is finished the shell will be closed. We can see in the screenshot that Connection to poftut1 closed
我们可以通过提供COMMAND来简单地运行命令。 提供的命令将在不创建新进程的情况下运行。 在此示例中,我们将运行ls
命令。 命令执行完成后,将关闭外壳。 我们可以在屏幕截图中看到Connection to poftut1 closed
$ exec ls

提供参数(Provide Parameter)
We can also provide parameter to the given command. We will add parameter after the command. In this example we will execute ls /
.
我们还可以为给定命令提供参数。 我们将在命令后添加参数。 在此示例中,我们将执行ls /
。
$ exec ls /
在空环境下运行命令 (Run Command with Empty Environment)
Linux bash provides environments to the forked processes. Environment variables are used provides information about user, system, binary files etc. By default exec
command also inherits current bash environment. We can disable environment inheritance and provide empty environment with -c
option.
Linux bash为分叉的进程提供了环境。 使用环境变量可提供有关用户,系统,二进制文件等的信息。默认情况下, exec
命令还将继承当前的bash环境。 我们可以禁用环境继承,并使用-c
选项提供空环境。
$ exec -c whoami
翻译自: https://www.poftut.com/linux-bash-exec-command-tutorial-examples-execute-command/
bash linux命令