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 "$@" ```