From a0c86ee5c0f6f9d0eac4a1e2539002d903f04422 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Fri, 2 Mar 2018 15:36:14 +0100 Subject: nq: write_execline: avoid unnecessary quoting --- nq.c | 24 +++++++++++++++++------- 1 file 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, "'"); } } -- cgit 1.4.1