From cd2fcca16e5ceb057687065d26e3fe4a6bd6276d Mon Sep 17 00:00:00 2001 From: Mingye Wang Date: Fri, 26 Feb 2016 06:00:59 -0500 Subject: [PATCH] Updated SC2039 (markdown) --- SC2039.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SC2039.md b/SC2039.md index 56e0be5..c92ab18 100644 --- a/SC2039.md +++ b/SC2039.md @@ -101,7 +101,8 @@ grep aaa <<< "$g" POSIX: ```sh -printf '%s' "$g" | grep aaa # since we want to avoid `echo` +# not exactly the same -- <<< adds a trailing \n if $g doesn't end with \n +printf '%s' "$g" | grep aaa ``` ### echo flags @@ -138,7 +139,10 @@ POSIX: # TODO: Interpret it back to printf escapes for hard-to-copy chars like \t? # See also: http://git.savannah.gnu.org/cgit/libtool.git/tree/gl/build-aux/funclib.sh?id=c60e054#n1029 reuse_quote()( - for i; do echo -n \'; echo -n "$i" | sed -e "s/'/'\\\\''/g"; echo -n "' "; done + for i; do + __i_quote=$(printf '%s\n' "$i" | sed -e "s/'/'\\\\''/g"; echo x) + printf "'%s'" "${__i_quote%x}" + done ) reuse_quote "$@" ```