aboutsummaryrefslogtreecommitdiff
path: root/run.c
diff options
context:
space:
mode:
Diffstat (limited to 'run.c')
-rw-r--r--run.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/run.c b/run.c
index 136e20a..2bef988 100644
--- a/run.c
+++ b/run.c
@@ -1983,6 +1983,13 @@ void backsub(char **pb_ptr, const char **sptr_ptr) /* handle \\& variations */
{ /* sptr[0] == '\\' */
char *pb = *pb_ptr;
const char *sptr = *sptr_ptr;
+ static bool first = true;
+ static bool do_posix = false;
+
+ if (first) {
+ first = false;
+ do_posix = (getenv("POSIXLY_CORRECT") != NULL);
+ }
if (sptr[1] == '\\') {
if (sptr[2] == '\\' && sptr[3] == '&') { /* \\\& -> \& */
@@ -1992,6 +1999,9 @@ void backsub(char **pb_ptr, const char **sptr_ptr) /* handle \\& variations */
} else if (sptr[2] == '&') { /* \\& -> \ + matched */
*pb++ = '\\';
sptr += 2;
+ } else if (do_posix) { /* \\x -> \x */
+ sptr++;
+ *pb++ = *sptr++;
} else { /* \\x -> \\x */
*pb++ = *sptr++;
*pb++ = *sptr++;