Index: bin/sh/histedit.c =================================================================== --- bin/sh/histedit.c +++ bin/sh/histedit.c @@ -256,7 +256,6 @@ int histcmd(int argc, char **argv __unused) { - int ch; const char *editor = NULL; HistEvent he; int lflg = 0, nflg = 0, rflg = 0, sflg = 0; @@ -278,25 +277,29 @@ if (argc == 1) error("missing history argument"); - while (not_fcnumber(*argptr) && (ch = nextopt("e:lnrs")) != '\0') - switch ((char)ch) { - case 'e': - editor = shoptarg; - break; - case 'l': - lflg = 1; - break; - case 'n': - nflg = 1; - break; - case 'r': - rflg = 1; - break; - case 's': - sflg = 1; - break; - } - + while (not_fcnumber(*argptr)) + do { + switch (nextopt("e:lnrs")) { + case 'e': + editor = shoptarg; + break; + case 'l': + lflg = 1; + break; + case 'n': + nflg = 1; + break; + case 'r': + rflg = 1; + break; + case 's': + sflg = 1; + break; + case '\0': + goto operands; + } + } while (nextopt_optptr != NULL); +operands: savehandler = handler; /* * If executing... Index: bin/sh/options.c =================================================================== --- bin/sh/options.c +++ bin/sh/options.c @@ -589,6 +589,9 @@ shoptarg = p; p = NULL; } - nextopt_optptr = p; + if (p != NULL && *p != '\0') + nextopt_optptr = p; + else + nextopt_optptr = NULL; return c; } Index: bin/sh/tests/builtins/Makefile =================================================================== --- bin/sh/tests/builtins/Makefile +++ bin/sh/tests/builtins/Makefile @@ -94,6 +94,7 @@ ${PACKAGE}FILES+= export1.0 ${PACKAGE}FILES+= fc1.0 ${PACKAGE}FILES+= fc2.0 +${PACKAGE}FILES+= fc3.0 fc3.0.stdout fc3.0.stderr ${PACKAGE}FILES+= for1.0 ${PACKAGE}FILES+= for2.0 ${PACKAGE}FILES+= for3.0 Index: bin/sh/tests/builtins/fc3.0 =================================================================== --- /dev/null +++ bin/sh/tests/builtins/fc3.0 @@ -0,0 +1,9 @@ +export PS1='_ ' # cannot predict whether ran by root or not + +echo ': command1 +: command2 +: command3 +: command4 +fc -l -n -1 +fc -ln 2 3 +' | ENV= HISTFILE=/dev/null ${SH} +m -i Index: bin/sh/tests/builtins/fc3.0.stderr =================================================================== --- /dev/null +++ bin/sh/tests/builtins/fc3.0.stderr @@ -0,0 +1 @@ +_ _ _ _ _ _ _ _ Index: bin/sh/tests/builtins/fc3.0.stdout =================================================================== --- /dev/null +++ bin/sh/tests/builtins/fc3.0.stdout @@ -0,0 +1,3 @@ +: command4 +: command2 +: command3