TL;DR: awk and backslashes in the replacement argument of gsub is ugly. With GNU Awk 4.0.2 we have:
$ echo '\' | awk '{ gsub("\\\\", "\\\\\\\\\\\\\\\\"); print }' \\\\\\\\ and with GNU Awk 4.1.4 (and newer) we have: $ echo '\' | awk '{ gsub("\\\\", "\\\\\\\\\\\\\\\\"); print }' \\\\ This results in too much backslashes in /etc/issues for users of the former version. For the glory details I recommend reading through https://www.gnu.org/software/gawk/manual/html_node/Gory-Details.html https://bugs.debian.org/909147 As it's awkward to come up with an expression that does the same on both versions (e.g. using --posix) use sed instead. Signed-off-by: Uwe Kleine-König <u.kleine-koe...@pengutronix.de> --- scripts/lib/ptxd_make_xpkg_pkg.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/lib/ptxd_make_xpkg_pkg.sh b/scripts/lib/ptxd_make_xpkg_pkg.sh index 5e69cefdc85d..685f4e549446 100644 --- a/scripts/lib/ptxd_make_xpkg_pkg.sh +++ b/scripts/lib/ptxd_make_xpkg_pkg.sh @@ -584,13 +584,13 @@ install replace figlet: local escapemode="$2" figlet -d "${PTXDIST_SYSROOT_HOST}/share/figlet" -- "${value}" | \ case "$escapemode" in - # a lot of leaning toothpicks because we need to escape a literal - # '\' with '\\' on multiple levels: - # - one level for the string inside awk: \\\\\\\\\\\\\\\\ -> \\\\\\\\ - # - one level for the shell string after sed -e: -> \\\\ - # - one level for the s expression inside sed: -> \\ - # - and finally, one level for /etc/issue: -> \ - etcissue) awk '{ gsub("\\\\", "\\\\\\\\\\\\\\\\"); print }' ;; + # /etc/issue needs each backslash quoted by another backslash. As + # the string is interpreted by the shell once more below, another + # level of quoting is needed such that every \ in the output of + # figlet needs to be replaced by \\\\. As a \ in sed needs to be + # quoted, too, this results in eight backslashes in the replacement + # string. + etcissue) sed 's,\\,\\\\\\\\,';; *) ;; esac | \ awk '{ if ($0 !~ "^ *$") printf("%s\\n", $0) }' # newlines for sed -- 2.19.0 _______________________________________________ ptxdist mailing list ptxdist@pengutronix.de