Added proposed printf %q

Mingye Wang
2015-09-20 23:03:02 -04:00
parent a86852db74
commit e896f35440

@@ -107,4 +107,40 @@ printf '%s' "$g" | grep aaa # since we want to avoid `echo`
### echo flags ### echo flags
See koalaman/shellcheck#461. 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.