LinuxCommandLibrary

exec

shell builtin to replace process with command

TLDR

Execute a specific command

$ exec [command -with -flags]
copy
Execute with empty environment
$ exec -c [command -with -flags]
copy
Execute as login shell
$ exec -l [command -with -flags]
copy
Execute with different name
$ exec -a [name] [command -with -flags]
copy

SYNOPSIS

exec [options] [command] [arguments]

DESCRIPTION

exec replaces the current shell process with the specified command without creating a child process. When exec completes, the shell session ends because the shell process no longer exists.
Built-in shell command commonly used in shell scripts and wrapper scripts.

PARAMETERS

-c

Execute with mostly empty environment
-l
Pass command as login shell
-a name
Pass name as argv[0] to command

CAVEATS

Shell built-in command. The shell terminates after exec completes. File descriptors can be redirected before exec. Used in init scripts and process management.

SEE ALSO

bash(1), sh(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community