diff options
author | Leah Neukirchen <leah@vuxu.org> | 2018-03-02 15:36:14 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2018-03-02 15:36:14 +0100 |
commit | a0c86ee5c0f6f9d0eac4a1e2539002d903f04422 (patch) | |
tree | 36be2a135350fdeda2e15547bf04060dcd5ad0f9 | |
parent | b64d79ee0d4119edf5f0e1f5ce72a8c976724bd4 (diff) | |
download | nq-a0c86ee5c0f6f9d0eac4a1e2539002d903f04422.tar.gz nq-a0c86ee5c0f6f9d0eac4a1e2539002d903f04422.tar.xz nq-a0c86ee5c0f6f9d0eac4a1e2539002d903f04422.zip |
nq: write_execline: avoid unnecessary quoting
-rw-r--r-- | nq.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/nq.c b/nq.c index d6208a1..36feabd 100644 --- a/nq.c +++ b/nq.c @@ -84,14 +84,24 @@ write_execline(int fd, int argc, char *argv[]) swrite(fd, "exec"); for (i = 0; i < argc; i++) { - swrite(fd, " '"); - for (s = argv[i]; *s; s++) { - if (*s == '\'') - swrite(fd, "'\\''"); - else - write(fd, s, 1); + if (!strpbrk(argv[i], + "\001\002\003\004\005\006\007\010" + "\011\012\013\014\015\016\017\020" + "\021\022\023\024\025\026\027\030" + "\031\032\033\034\035\036\037\040" + "`^#*[]=|\\?${}()'\"<>&;\177")) { + swrite(fd, " "); + swrite(fd, argv[i]); + } else { + swrite(fd, " '"); + for (s = argv[i]; *s; s++) { + if (*s == '\'') + swrite(fd, "'\\''"); + else + write(fd, s, 1); + } + swrite(fd, "'"); } - swrite(fd, "'"); } } |