Linux Bash Exec Command Tutorial with Examples To Execute Command

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-bash-exec-command-tutorial-examples-execute-command/
PINTEREST
PINTEREST
INSTAGRAM

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.

Syntax

Syntax of exec command is like below.

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.

and than we can run it directly without needing exec command like below.

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

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 / .

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.

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-bash-exec-command-tutorial-examples-execute-command/
PINTEREST
PINTEREST
INSTAGRAM

LEARN MORE  Linux Bash Default Environment Variables

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)