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.

9
  • I guess f2() ( … ) being executed in a subshell and outside the current running environment is one thing and the freedom to localize some and not other vars as well as inherit others is another thing. Commented Jul 30 at 16:45
  • 2
    subshell environment is not limited to variables. Also includes options, aliases, functions, opened files, limits, working directory, umask, etc. Commented Jul 30 at 18:16
  • 1
    Note that compound-command is not limited to { ...; } and (...), there are many others including while/for loops, case/if constructs and even... function definitions. For example, f() g() for i do w; done defines a f function that defines a g function as a for loop. Commented Jul 30 at 18:24
  • 1
    @ilkkachu, thanks. I stand corrected. bash and yash (the only two maintained shells I know where function body can't be any command) actually reject f() g() { : ;} like they reject functions with simple command as body. Commented Jul 30 at 21:05
  • 1
    Never mind the ( ) { } differences (which I have exploited and/or misused), how am I just learning about the redirect part?! f() { echo hello ; } >/tmp/foofile. I really should RTFM. Commented Jul 30 at 21:33