construct

Bash subshell function body

Runs a function body in a subshell environment; shell variable changes do not persist in the caller, but filesystem side effects can persist.

Formal Syntax & Structure

bash syntaxbash
name() ( commands )

Return Value

exit status

Runs a function body in a subshell environment; shell variable changes do not persist in the caller, but filesystem side effects can persist.

Working Example

Example Snippetbash
state=originalchange() { state=changed; }isolate() ( state=isolated; printf '%s\n' "$state" )changeisolateprintf '%s\n' "$state"
Bash Reference