Go to file
2024-04-11 21:27:43 -05:00
src initial import 2024-04-11 20:45:49 -05:00
.gitignore initial import 2024-04-11 20:45:49 -05:00
Cargo.lock initial import 2024-04-11 20:45:49 -05:00
Cargo.toml initial import 2024-04-11 20:45:49 -05:00
LICENSE initial import 2024-04-11 20:45:49 -05:00
README.md add readme 2024-04-11 21:27:43 -05:00


sh quoting for your sh scripts. Or for your rust stuff. Whichever.


shq is mostly interesting for use when escaping unknown strings so here's an example of that:

trap "$(shq echo "your first arg was $1 and your random token was $RANDOM")" 2

This will echo your first arg safely as well as a random number whenever you press Ctrl-C. Significantly, these will be the values at the time the trap was created.

How it works

In sh, a single quote (') opens a string which may contain any character other than another single quote. A single quote may be included in a double quoted string. And finally, two strings may be concatenated by simply shoving them together. Thus, we get echo 'this string'"'"'s very cool' which produces this string's very cool. An alternate version which uses echo 'this string'\''s very cool' is possible. I don't like \.

Comparison to other tools

coreutils's as well as possibly other implementations of the printf shell scripting tool have a %q format specifier which does largely the same thing as this tool. Some of these use backslashes which may be more or less compatible with your particular use case than the reliance on single quote strings.