[DTrace-devel] [PATCH 19/20] test: allow test options to be set to "-e"
Kris Van Hees
kris.van.hees at oracle.com
Wed Jul 27 21:35:45 UTC 2022
On Wed, May 11, 2022 at 10:13:01PM +0100, Nick Alcock via DTrace-devel wrote:
> The curse of echo caught us again. Using printf keeps the -e, but even
> then we have to doble-quote the argument because one layer of quotes
> will be eaten by the eval, and printf with more args than format string
> args reuses the format string over and over again: if it's %s, this
> effectively squashes the args together with intervening spaces removed.
>
> Signed-off-by: Nick Alcock <nick.alcock at oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>
... but it really should have had a test
I will add one (in the interest of time)
... and queued for dev,
> ---
> runtest.sh | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/runtest.sh b/runtest.sh
> index 387907a8df4a..c9a23ba0ad08 100755
> --- a/runtest.sh
> +++ b/runtest.sh
> @@ -177,14 +177,17 @@ extract_options()
>
> _pid='$_pid'
>
> - # This trick is because printf squashes out spaces, echo -e -e foo
> - # prints 'foo', and echo -e -- "foo" prints "-- foo".
> + # This trick is because printf with a straight eval ends up called
> + # with more args than format string items and squashes out spaces,
> + # echo -e -e foo prints 'foo', and bash's builtin echo -e -- "foo"
> + # prints "-- foo". coreutils echo does the right thing, but is more
> + # expensive than the builtin printf, so use it only when needed.
>
> if [[ -n $val ]]; then
> if [[ -n $expand ]]; then
> - eval echo ''"$val"
> + eval printf "%s" \""$val"\"
> else
> - echo ''"$val"
> + printf "%s" ''"$val"
> fi
> fi
> return
> --
> 2.36.1.263.g194b774378.dirty
>
>
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel
More information about the DTrace-devel
mailing list