diff options
author | jilles <jilles@FreeBSD.org> | 2011-05-05 20:55:55 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2011-05-05 20:55:55 +0000 |
commit | 5a49f52603051288db09536911ad4c73579aeb99 (patch) | |
tree | f65bdb50369c1f6631b70c1264abbc69f9ce4513 /bin/sh/mksyntax.c | |
parent | 7ec44d66a6202d6f9bf5a7ef04ba108896f96bea (diff) | |
download | FreeBSD-src-5a49f52603051288db09536911ad4c73579aeb99.zip FreeBSD-src-5a49f52603051288db09536911ad4c73579aeb99.tar.gz |
sh: Add $'quoting' (C-style escape sequences).
A string between $' and ' may contain backslash escape sequences similar to
the ones in a C string constant (except that a single-quote must be escaped
and a double-quote need not be). Details are in the sh(1) man page.
This construct is useful to include unprintable characters, tabs and
newlines in strings; while this can be done with a command substitution
containing a printf command, that needs ugly workarounds if the result is to
end with a newline as command substitution removes all trailing newlines.
The construct may also be useful in future to describe unprintable
characters without needing to write those characters themselves in 'set -x',
'export -p' and the like.
The implementation attempts to comply to the proposal for the next issue of
the POSIX specification. Because this construct is not in POSIX.1-2008,
using it in scripts intended to be portable is unwise.
Matching the minimal locale support in the rest of sh, the \u and \U
sequences are currently not useful.
Exp-run done by: pav (with some other sh(1) changes)
Diffstat (limited to 'bin/sh/mksyntax.c')
-rw-r--r-- | bin/sh/mksyntax.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/bin/sh/mksyntax.c b/bin/sh/mksyntax.c index 6bd1390..9aa7450 100644 --- a/bin/sh/mksyntax.c +++ b/bin/sh/mksyntax.c @@ -64,6 +64,7 @@ struct synclass synclass[] = { { "CWORD", "character is nothing special" }, { "CNL", "newline character" }, { "CBACK", "a backslash character" }, + { "CSBACK", "a backslash character in single quotes" }, { "CSQUOTE", "single quote" }, { "CDQUOTE", "double quote" }, { "CENDQUOTE", "a terminating quote" }, @@ -224,6 +225,7 @@ main(int argc __unused, char **argv __unused) init(); fputs("\n/* syntax table used when in single quotes */\n", cfile); add("\n", "CNL"); + add("\\", "CSBACK"); add("'", "CENDQUOTE"); /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */ add("!*?[=~:/-", "CCTL"); |