Bash - Exec (No New Process) - builtin command

Bash Liste Des Attaques Ovh

About

If command is specified, it replaces the shell. No subshell (ie new process) is created.

The shell:

  • terminates if there is a command.
  • continues if there is only a redirection management

Example

Without command: for redirection management

You can use exec when you want to capture all stdout of a series of command.

When a command is not specified:

  • any redirections take effect in the current shell, and the return status is 0.
  • if there is a redirection error, the return status is 1.

Example:

# Save the original stdout to the file descriptor (3)
exec 3>&1

# Redirect stdout to the file output.txt
exec 1> | /dev/shm/output.txt

# Command that output to stdout
# ............

# Restore original stdout file descriptor
exec 1>&3

# Close file descriptor 3
exec 3>&-

# Now you can read the captured output from the `output.txt` file descriptor
cat /dev/shm/output.txt

Syntax

exec [-cl] [-a name] [command [arguments]]

where:

  • arguments become the arguments to command.
  • -l the shell places a dash at the beginning of the zeroth arg passed to command. This is what login(1) does.
  • -c option causes command to be executed with an empty environment.
  • -a : the shell passes name as the zeroth argument to the executed command.

Return value

If command cannot be executed for some reason,

Without command, redirections takes effect

If command is not specified, any redirections take effect in the current shell, and the return status is 0. If there is a redirection error, the return status is 1.

Documentation / Reference





Discover More
Bash Liste Des Attaques Ovh
Bash - Builtin Commands

builtin refers to: a builtin command. See or to the specific builtin command. See (useful when defining a function whose name is the same as a shell builtin) The builtin command execute the specified...
Bash Liste Des Attaques Ovh
Bash - Script Execution

script execution
Bash Liste Des Attaques Ovh
Bash - process

This article is the bash Process. To see how to manage another general linux process, see The process running the command is created. The process inherits the stdin, stdout, and stderr from...
Bash Liste Des Attaques Ovh
What is a Bash or Shell Script?

This page is Os Shell scripts (with a accent on the Bash shell) A Bash or Shell Script is a text file that: has a shebang has the executable permission. File extensions are meaningless in UNIX,...



Share this page:
Follow us:
Task Runner