All of lore.kernel.org
 help / color / mirror / Atom feed
* eval and export behave differently together in dash and ash than in bash, zsh, and ksh
@ 2014-02-14 18:29 Dan Kegel
  2014-02-14 18:46 ` Eric Blake
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Kegel @ 2014-02-14 18:29 UTC (permalink / raw)
  To: dash

The script

eval export dir=~$LOGNAME
echo $dir

eval dir2=~$LOGNAME
echo $dir2

produces different results on different shells.

bash  (4.2-2ubuntu2.1) (with and without --posix)
zsh (4.3.17-1ubuntu1)
ksh (93u-1)
produce

/home/buildbot
/home/buildbot

dash (0.5.7-2ubuntu2)
ash (0.5.7-2ubuntu2)
produce

~buildbot
/home/buildbot

The easy workaround is to use the older form

eval dir=~$LOGNAME
export dir

but it'd be nice if that weren't needed.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: eval and export behave differently together in dash and ash than in bash, zsh, and ksh
  2014-02-14 18:29 eval and export behave differently together in dash and ash than in bash, zsh, and ksh Dan Kegel
@ 2014-02-14 18:46 ` Eric Blake
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Blake @ 2014-02-14 18:46 UTC (permalink / raw)
  To: Dan Kegel, dash

[-- Attachment #1: Type: text/plain, Size: 1464 bytes --]

On 02/14/2014 11:29 AM, Dan Kegel wrote:
> The script
> 
> eval export dir=~$LOGNAME
> echo $dir

This has been discussed by the POSIX folks.  See:
http://austingroupbugs.net/view.php?id=351

The standard added the definition of a 'declaration utility', which can
evaluate its arguments in assignment context, and marked that 'export'
is one such utility:

>> At line 74276 (XCU export DESCRIPTION), add:
>> The export special built-in shall be a declaration utility. Therefore,
>> if export is recognized as the command word of a simple command, then
>> subsequent words of the form name=word shall be expanded in an
>> assignment context. See Section 2.9.1.

Meanwhile, 'eval' is not allowed to be a declaration utility.  Thus,
once this POSIX interpretation is made live in Issue 8 (currently still
unreleased), a conforming shell would have to evaluate this as:

eval export dir=~$LOGNAME      # not in assignment context
eval 'export' 'dir=~buildbot'  # actual arguments passed to eval
export dir=~buildbot           # declaration context, do tilde expansion
dir gets /home/buildbot

ksh and bash are compliant, dash needs to be patched.

However, as Issue 8 POSIX is not yet released, dash is not yet
non-compliant, and you are correct that workarounds exist while waiting
for someone to write the patch for dash.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-02-14 18:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-14 18:29 eval and export behave differently together in dash and ash than in bash, zsh, and ksh Dan Kegel
2014-02-14 18:46 ` Eric Blake

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.