Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 1
    Subshells? Or scripts executed in a new shell? Can you provide a minimal example of this behaviour? Commented Jun 25, 2018 at 4:54
  • 2
    Possible duplicate of difference between "function foo() {}" and "foo() {}" Commented Jun 25, 2018 at 5:03
  • AFAICT, both bash -c 'foo() { echo bar; }; (foo)' and bash -c 'function foo { echo bar; }; (foo)' work fine, and the linked question's answers do not mention any difference related to export behaviour. (And neither bash -c 'function foo { echo bar; }; bash -c foo' nor bash -c 'foo() { echo bar; }; bash -c foo' work: both fail with foo not being found.) Commented Jun 25, 2018 at 5:04
  • @muru I guess not subshells - in my case the bash script would be sourced by the shell, and then the bash functions executed in the new shell (I guess that's not a subshell). Commented Jun 25, 2018 at 5:09
  • 1
    @AlexanderMills "in the new shell"? Is that new shell the same that sourced it? Can't you just show what you're doing? Commented Jun 25, 2018 at 5:41