[U-Boot] [PATCH] hush: when a variable expansion is empty, don't drop the parameter
Russell King - ARM Linux
linux at arm.linux.org.uk
Thu Feb 27 11:49:26 CET 2014
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.
More information about the U-Boot
mailing list