[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

POSIX shell clarification



(I'm not sure where to send this, but it's of interest for making
packages containing shell scripts policy-compliant, which I'm currently
trying to do, so...)

bash and dash differ in their handling of variable assignments. To wit:

  bash$ FOO=$(false) || echo failed
  failed

  dash$ FOO=$(false) && echo worked
  worked

I'm not sure which is correct. I've looked at the bash and dash
manpages, and SUSv2 at opengroup.org (unfortunately, I can't find a copy
of POSIX 1003.2 online--- either my Google skills are rusty, or you have
to pay for it), and they seem to be pretty much in agreement about how
simple commands are parsed, but don't say anything about what the exit
status of a simple command that doesn't actually have any commands in it
is. Am I missing something?

If the answer is no, and there really is nothing specified here in the
standard, then I assume it's OK to file bugs on any package[1] using
#!/bin/sh that depends on bash's current behavior of propagating the
exit status of the last command ran while expanding values for variable
assignments in a simple command containing nothing else (i.e. one
affecting the current shell environment).

[1] No, I'm not going to mass-file anything, I'm just curious. I'm about
to fix the one script where this bit me anyway, and then get back to
Christmas shopping.

-- 
things change.
decklin@red-bean.com



Reply to: