Inconsistent splitting of results of $(Command Substitution)
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
dash (Ubuntu) |
New
|
Undecided
|
Unassigned |
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'"
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
ProcVersionSign
Uname: Linux 4.4.0-66-generic x86_64
NonfreeKernelMo
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)