[PATCH 3/6] fc: only parse old=new if -s, per POSIX

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Before (erroneously replaced):
	$ a=b set
	...
	$ fc a=b
	8
	,
	b=b set
After (used as search string):
	$ fc a=b
	8
	,
	a=b set

Reported-by: Harald van Dijk <harald@xxxxxxxxxxx>
Reported-in: https://marc.info/?l=dash&m=154707728009743&w=2
---
 src/histedit.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/src/histedit.c b/src/histedit.c
index 28956ec..24631ca 100644
--- a/src/histedit.c
+++ b/src/histedit.c
@@ -288,21 +288,18 @@ histcmd(int argc, char **argv)
 	}
 
 	/*
-	 * If executing, parse [old=new] now
+	 * If -s is specified, accept [old=new] first only
 	 */
-	if (lflg == 0 && argc > 0 &&
-	     ((repl = strchr(argv[0], '=')) != NULL)) {
-		pat = argv[0];
-		*repl++ = '\0';
-		argc--, argv++;
+	if (sflg) {
+		if (argc > 0 && ((repl = strchr(argv[0], '=')) != NULL)) {
+			pat = argv[0];
+			*repl++ = '\0';
+			argc--, argv++;
+		}
+		if (argc >= 2)
+			sh_error("too many args");
 	}
 
-	/*
-	 * If -s is specified, accept only one operand
-	 */
-	if (sflg && argc >= 2)
-		sh_error("too many args");
-
 	/*
 	 * determine [first] and [last]
 	 */
-- 
2.30.2

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux