bash linux命令_Linux Bash Exec命令教程以及执行命令的示例

bash linux命令

bash linux命令

Linux bash provides different commands for daily usage. execcommand 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
Run Command 
Run Command
运行命令

提供参数(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
LEARN MORE  setenv Command Tutorial To Add, Delete and Change Environment Variables In Linux
了解更多setenv命令教程,用于在Linux中添加,删除和更改环境变量

翻译自: https://www.poftut.com/linux-bash-exec-command-tutorial-examples-execute-command/

bash linux命令

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值