Skip to contentSkip to conversation

dash drops exported bash functions

DISCUSSION Joachim Breitner 2 participants 3 messages Feb 10, 2016

lore
Share & tools
lore
#0 lore raw

Dear dash developers,

a change in 0.5.8, very likely this one
http://git.kernel.org/cgit/utils/dash/dash.git/commit/?id=46d3c1a614f11f0d40a7e73376359618ff07abcd
broke the exporting of bash shell functions via the environment.

The attached script shows the breakage, as it outputs

$ ./exporttest.sh 
exportest called ()
Setting up environment
Calling myself
exportest called (1)
function foo successfully called
Calling myself directly
exportest called (2)
function foo successfully called
Calling myself via dash
exportest called (3)
/tmp/exporttest.sh: Zeile 33: foo: Kommando nicht gefunden.
Done

Exporting bash functions via the environment might be a rarely used feature, but it is used in practice, unfortunately (otherwise I wouldn’t have noticed this).

Thanks,
Joachim

Signature · 4 lines
Joachim “nomeata” Breitner
  [email protected] • https://www.joachim-breitner.de/
  XMPP: [email protected] • OpenPGP-Key: 0xF0FBF51F
  Debian Developer: [email protected]
#1 lore raw
Quoted 5 lines · Joachim Breitner

Dear dash developers,

a change in 0.5.8, very likely this one
http://git.kernel.org/cgit/utils/dash/dash.git/commit/?id=46d3c1a614f11f0d40a7e73376359618ff07abcd
broke the exporting of bash shell functions via the environment.

Not a bug. POSIX says that on shell startup, the behavior of any inherited environment variables that do not start with a proper shell name is undefined; and allows shells to scrub such items out of the environment on startup. Just because bash does not scrub them (but instead treats them as shell function imports) does not mean dash has to behave the same.

That said, preserving any unusable environment variables unchanged, rather than scrubbing them, may be slightly nicer behavior, but I'm not sure it's worth the bloat to dash to do so.

Quoted 4 lines

Exporting bash functions via the environment might be a rarely used feature, but it is used in practice, unfortunately (otherwise I wouldn’t have noticed this).

Exporting bash functions is only usable if you plan on directly invoking bash. Don't drag dash into the mess. Inserting a dash child in between a bash parent and grandchild means all bets are off for whether the grandparent can export anything to the grandchild.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw

Dear Eric,

Am Mittwoch, den 10.02.2016, 08:54 -0700 schrieb Eric Blake:

Quoted 14 lines · Joachim Breitner
Quoted 5 lines

Dear dash developers,

a change in 0.5.8, very likely this one
http://git.kernel.org/cgit/utils/dash/dash.git/commit/?id=46d3c1a614f11f0d40a7e73376359618ff07abcd
broke the exporting of bash shell functions via the environment.

Not a bug. POSIX says that on shell startup, the behavior of any inherited environment variables that do not start with a proper shell name is undefined; and allows shells to scrub such items out of the environment on startup.  Just because bash does not scrub them (but instead treats them as shell function imports) does not mean dash has to behave the same.

Quoted 3 lines

That said, preserving any unusable environment variables unchanged, rather than scrubbing them, may be slightly nicer behavior, but I'm not sure it's worth the bloat to dash to do so.

I’m not versed in reading POSIX,, so I won’t argue with that (although I could not find a reference), but let me point out 8.1 "8.1 Environment Variable Definition" of "The Open Group Base Specifications Issue 7" says
“Other characters may be permitted by an implementation; applications shall tolerate the presence of such names.”

But it is not a big deal now, as the application suffering from this issue will likely have to work-around this (or fix this, depending on the POV) anyways.

Greetings,
Joachim

Signature · 4 lines
Joachim “nomeata” Breitner
  [email protected] • https://www.joachim-breitner.de/
  XMPP: [email protected] • OpenPGP-Key: 0xF0FBF51F
  Debian Developer: [email protected]