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.

6
  • 2
    Where is this documented? Commented Aug 16, 2016 at 20:30
  • Hmm, not sure where this is documented, but the return code from a variable assignment is the return code of the evaluation of the right hand side. That's why x=$(Nosuchcommand) returns an exit code of 127 because that's the standard "command not found" exit code. Commented Aug 16, 2016 at 20:36
  • man bash and search for EXIT STATUS. Is this the location that is being sought? Commented Aug 16, 2016 at 20:43
  • @TimothyMartin Not sure ... the man page talks about "commands" and "built-in commands", but that's where I'm confused. I never would have thought setting a variable was a "command" (although something like $(command) is obviously a command). Commented Aug 17, 2016 at 12:14
  • It's not entirely accurate, but I like to think of an assignment statement as a pre-command assignment that just happens to precede a null command that behaves like :. The assignments affect the current shell just like redirections on exec with no arguments affect the current shell. Commented Aug 17, 2016 at 17:12