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*

8
  • 3
    Could this affect any other Bash-like shell then, like Zsh? Commented Sep 24, 2014 at 22:52
  • 3
    @user815423426 No, zsh doesn't have this feature. Ksh has it but implemented differently, I think functions can only be transmitted in very narrow circumstances, only if the shell forks, not through the environment. Commented Sep 24, 2014 at 23:19
  • 20
    @user815423426 rc is the other shell that passes functions in the environment, but its with variable with names prefixed with "fn_" and they are only interpreted when invoked. Commented Sep 24, 2014 at 23:48
  • 14
    @gnclmorais You mean you run export bar='() { echo "bar" ; }'; zsh -c bar and it displays bar rather than zsh:1: command not found: bar? Are you sure you aren't confusing the shell you're invoking with the shell that you're using to set up the test? Commented Sep 25, 2014 at 13:06
  • 3
    The most recent (second!) bash update shows the exported function as environment variable BASH_FUNC_foo()=..., not foo=() ..., a very important difference, as it also makes it impossible to override common tools like grep and cat by crafting environment variables with these names and putting function definitions in them, as manually setting var()="value" isn't valid syntax and will produce an error. Commented Sep 28, 2014 at 0:15