Public bug reported:

The man page says, under "Word Expansions", that output from Command
Substitution will be later split into fields (unless IFS is null).

Therefore the statement

   foo=$(echo xxx bar=yyy)

should expand to

   foo=xxx bar=yyy

and when executed, set two variables foo and bar.

However dash does not do this.  Instead, the Command Substitution output
is not split, and the result is the same as

   foo="xxx bar=yyy"

which sets a single variable.

HOWEVER, inside a function, dash *does* split the result of Command
Substitution if it is part of a 'local' variable declaration.

This seems inconsistent: One or the other case must be a bug.

Comment: Despite what the man says, splitting Command Substitution
results is probably not desirable and would be incompatible with bash
(which AFAIK never splits Command Subst output).  I can't say what POSIX
mandates about this.

#!/usr/bin/env dash

func() {
  echo "IFS='$IFS'"
         gvar=$(echo "11 y=22")
  local  lvar=$(echo "33 z=44")
  echo "gvar=$gvar"
  echo "y=$y"
  echo "lvar=$lvar"
  echo "z=$z"
}

func

# RESULTS:
#
# IFS='
# '
# gvar=11 y=22
# y=
# lvar=33
# z=44

ProblemType: Bug
DistroRelease: Ubuntu 16.04
Package: dash 0.5.8-2.1ubuntu2
ProcVersionSignature: Ubuntu 4.4.0-66.87-generic 4.4.44
Uname: Linux 4.4.0-66-generic x86_64
NonfreeKernelModules: nvidia_uvm nvidia_drm nvidia_modeset nvidia
ApportVersion: 2.20.1-0ubuntu2.5
Architecture: amd64
CurrentDesktop: Unity
Date: Fri Mar 10 16:33:07 2017
InstallationDate: Installed on 2017-01-19 (50 days ago)
InstallationMedia: Ubuntu 16.04.1 LTS "Xenial Xerus" - Release amd64 (20160719)
SourcePackage: dash
UpgradeStatus: No upgrade log present (probably fresh install)

** Affects: dash (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: amd64 apport-bug xenial

-- 
You received this bug notification because you are a member of Ubuntu
Touch seeded packages, which is subscribed to dash in Ubuntu.
https://bugs.launchpad.net/bugs/1671977

Title:
  Inconsistent splitting of results of $(Command Substitution)

Status in dash package in Ubuntu:
  New

Bug description:
  The man page says, under "Word Expansions", that output from Command
  Substitution will be later split into fields (unless IFS is null).

  Therefore the statement

     foo=$(echo xxx bar=yyy)

  should expand to

     foo=xxx bar=yyy

  and when executed, set two variables foo and bar.

  However dash does not do this.  Instead, the Command Substitution
  output is not split, and the result is the same as

     foo="xxx bar=yyy"

  which sets a single variable.

  HOWEVER, inside a function, dash *does* split the result of Command
  Substitution if it is part of a 'local' variable declaration.

  This seems inconsistent: One or the other case must be a bug.

  Comment: Despite what the man says, splitting Command Substitution
  results is probably not desirable and would be incompatible with bash
  (which AFAIK never splits Command Subst output).  I can't say what
  POSIX mandates about this.

  #!/usr/bin/env dash

  func() {
    echo "IFS='$IFS'"
           gvar=$(echo "11 y=22")
    local  lvar=$(echo "33 z=44")
    echo "gvar=$gvar"
    echo "y=$y"
    echo "lvar=$lvar"
    echo "z=$z"
  }

  func

  # RESULTS:
  #
  # IFS='
  # '
  # gvar=11 y=22
  # y=
  # lvar=33
  # z=44

  ProblemType: Bug
  DistroRelease: Ubuntu 16.04
  Package: dash 0.5.8-2.1ubuntu2
  ProcVersionSignature: Ubuntu 4.4.0-66.87-generic 4.4.44
  Uname: Linux 4.4.0-66-generic x86_64
  NonfreeKernelModules: nvidia_uvm nvidia_drm nvidia_modeset nvidia
  ApportVersion: 2.20.1-0ubuntu2.5
  Architecture: amd64
  CurrentDesktop: Unity
  Date: Fri Mar 10 16:33:07 2017
  InstallationDate: Installed on 2017-01-19 (50 days ago)
  InstallationMedia: Ubuntu 16.04.1 LTS "Xenial Xerus" - Release amd64 
(20160719)
  SourcePackage: dash
  UpgradeStatus: No upgrade log present (probably fresh install)

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/dash/+bug/1671977/+subscriptions

-- 
Mailing list: https://launchpad.net/~touch-packages
Post to     : touch-packages@lists.launchpad.net
Unsubscribe : https://launchpad.net/~touch-packages
More help   : https://help.launchpad.net/ListHelp

Reply via email to