Bash – Do functions run as subprocesses in Bash

bashfunctionprocess

In Advanced Bash-Scripting Guide, in example 27-4, 7-th line from the bottom, I've read this:

A function runs as a sub-process.

I did a test in Bash, and it seems that the above statement is wrong.

Searches on this site, Bash Man, and my search engine don't bring any light.

Do you have the answer and would like to explain?

Best Answer

The Advanced Bash-Scripting Guide is not always reliable and its example scripts contain out-dated practices such as using the effectively deprecated backticks for command substitution, i.e., `command` rather than $(command).

In this particular case, it’s blatantly incorrect.

The section on Shell Functions in the (canonical) Bash manual definitively states that

Shell functions are executed in the current shell context; no new process is created to interpret them.

Related Question