diff --git a/SC2039.md b/SC2039.md index fd23725..77c0b55 100644 --- a/SC2039.md +++ b/SC2039.md @@ -107,4 +107,40 @@ printf '%s' "$g" | grep aaa # since we want to avoid `echo` ### echo flags -See koalaman/shellcheck#461. \ No newline at end of file +See https://unix.stackexchange.com/tags/echo. + +### `${var/pat/replacement}` + +Bash: + +```Bash +echo "${TERM/%-256*}" +``` + +POSIX: + +```sh +echo "$TERM" | sed -e 's/-256.*$//g' +``` + +### `printf %q` + +Bash: + +```Bash +printf '%q ' "$@" +``` + +POSIX: + +```sh +# TODO: possibly interpret it back to printf escapes for hard-to-copy chars like \t +reuse_quote()( + for i; do echo -n \'; echo -n "$i" | sed -e "s/'/'\\\\''/g"; echo -n "' "; done +) +reuse_quote "$@" +``` + +## Exception + +Depends on what your expected POSIX shell providers would use. \ No newline at end of file