From a245b8525a55363546c2fae383c9616fccd78995 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 4 Aug 2024 16:55:05 -0700 Subject: [PATCH] Follow own advice about \ in shell double-quoted strings * lib/autoconf/headers.m4 (_AC_HEADERS_EXPANSION): * lib/m4sugar/m4sh.m4 (AS_ECHO): Go back to using '%s\n' instead of "%s\n". (AS_VAR_GET): Work around the quoting problem by using printf directly with "%s\\n" instead of AS_ECHO; this is safe now that we assume printf. --- doc/autoconf.texi | 8 ++++---- lib/autoconf/headers.m4 | 2 +- lib/m4sugar/m4sh.m4 | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 4d809153..cc588f49 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -18080,7 +18080,7 @@ only if you know that @var{foo}'s value cannot contain backslashes and cannot start with @samp{-}. Normally, @command{printf} is safer and easier to use than @command{echo} -and @command{echo -n}. Thus, you should use @command{printf "%s\n"} +and @command{echo -n}. Thus, you should use @command{printf '%s\n'} instead of @command{echo}, and similarly use @command{printf %s} instead of @command{echo -n}. @@ -19392,11 +19392,11 @@ The empty alternative is not portable. Use @samp{?} instead. For instance with Digital Unix v5.0: @example -> printf "foo\n|foo\n" | $EGREP '^(|foo|bar)$' +> printf 'foo\n|foo\n' | $EGREP '^(|foo|bar)$' |foo -> printf "bar\nbar|\n" | $EGREP '^(foo|bar|)$' +> printf 'bar\nbar|\n' | $EGREP '^(foo|bar|)$' bar| -> printf "foo\nfoo|\n|bar\nbar\n" | $EGREP '^(foo||bar)$' +> printf 'foo\nfoo|\n|bar\nbar\n' | $EGREP '^(foo||bar)$' foo |bar @end example diff --git a/lib/autoconf/headers.m4 b/lib/autoconf/headers.m4 index dec8538b..6f2a7b09 100644 --- a/lib/autoconf/headers.m4 +++ b/lib/autoconf/headers.m4 @@ -264,7 +264,7 @@ do _AC_CHECK_HEADER_COMPILE_FN()ac_fn_$1_check_header_compile "$LINENO" ]dnl [$ac_header ac_cv_header_$ac_cache "$ac_includes_default" if eval test \"x\$ac_cv_header_$ac_cache\" = xyes; then - printf "%s\n" "[#]define $ac_item 1" >> confdefs.h + printf '%s\n' "[#]define $ac_item 1" >> confdefs.h fi ac_header= ac_cache= elif test $ac_header; then diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4 index c973f177..a4f0f699 100644 --- a/lib/m4sugar/m4sh.m4 +++ b/lib/m4sugar/m4sh.m4 @@ -1113,7 +1113,7 @@ m4_define([AS_ECHO], dnl Extra quoting in case 's' or 'n' are user-defined macros when this dnl is expanded; they almost certainly aren't meant to be used here. dnl See bug 110377. -[printf "[%s\n]" $1]) +[printf '[%s\n]' $1]) # AS_ECHO_N(WORD) @@ -2051,7 +2051,7 @@ m4_define([AS_VAR_COPY], m4_define([AS_VAR_GET], [AS_LITERAL_WORD_IF([$1], [$$1], - [`eval 'as_val=${'_AS_ESCAPE([[$1]], [`], [\])'};AS_ECHO(["$as_val"])'`])]) + [`eval 'as_val=${'_AS_ESCAPE([[$1]], [`], [\])'};printf "[%s\\n]" "$as_val"'`])]) # AS_VAR_IF(VARIABLE, VALUE, IF-TRUE, IF-FALSE)