summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--nq.c24
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, "'");
 	}
 }