The file tmp.sh contains:

func() {

If the file is sourced using source tmp.sh, the function func works fine.

However, if the sourcing is done as cat tmp.sh | source /dev/stdin bash complaints:

-bash: func3: command not found

What is the difference between the two methods of sourcing? From source's perspective there should not be any difference since /dev/stdin would also be a file handle.

1 Answer 1


From bash(1): Each command in a pipeline is executed as a separate process (i.e., in a subshell).

The main shell does not have access to the definitions of its subshells.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .