From: Russell King - ARM Linux Date: Thu, 27 Feb 2014 10:49:26 +0000 Subject: [U-Boot] [PATCH] hush: when a variable expansion is empty, don't drop the parameter In-Reply-To: <20140227103924.GH21483@n2100.arm.linux.org.uk> References: <1393484106-16642-1-git-send-email-swarren@wwwdotorg.org> <20140227103924.GH21483@n2100.arm.linux.org.uk> Message-ID: <20140227104925.GA19843@n2100.arm.linux.org.uk> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Thu, Feb 27, 2014 at 10:39:24AM +0000, Russell King - ARM Linux wrote: > Standard shell will only drop an empty expansion if it's unquoted, so: > > a="1 2 3" > b=4 > c= > > echo $a $b $c > > ends up with arg1 = "1", arg2 = "2", arg3 = "3", arg4 = "4" and no arg5 > > echo "$a" "$b" "$c" > > ends up with arg1 = "1 2 3", arg2 = "4", arg3 = "" and no arg4 > > echo "$a $b $c" > > ends up with arg1 = "1 2 3 4 " and no arg2 > > If you'd like to check out this behaviour, this script will help you see > each argument as it was passed by the shell. > > #!/bin/sh > n=1 > for a in "$@"; do > echo "arg$n: \"$a\"" > n=$(($n + 1)) > done > > Getting this right matters, because it affects stuff like the ability > to make use of test -z / test -n, while preserving the ability to have > unquoted empty variables disappear from argument lists. There's another case where hush goes wrong: echo "Longblah: $foo" echo "Blah : $foo" should produce output where the :'s are aligned. Does in standard shells, but not in hush. I suspect this is because the word splitting/expansion isn't quite correct. Words inside quotes should not be split even after expansion - unless it's an expansion of "@". Note that also fixes the "$emptyvariable" problem at the root cause of the test -n/-z. -- FTTC broadband for 0.8mile line: now at 9.7Mbps down 460kbps up... slowly improving, and getting towards what was expected from it.