1

The file tmp.sh contains:

func() {
   ls
}

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.

6

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.