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 ((char)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,15 @@ +[ -n "$1" ] && { + o="$(ENV= HISTFILE=/dev/null $SH +m -i -c 'fc -l -1' 2>&1)" + [ "${o}" == 'fc: not compiled with history support' ] && exit 0 + exit 1 +} + +export PS1='_ ' # cannot predict whether ran by root or not + +echo 'break +continue +false +true +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 @@ +true +continue +false Index: bin/sh/tests/functional_test.sh =================================================================== --- bin/sh/tests/functional_test.sh +++ bin/sh/tests/functional_test.sh @@ -34,6 +34,10 @@ export SH=$(atf_config_get bin.sh.test_shell /bin/sh) + [ "$tc" == 'fc3.0' ] && + $SH "$SRCDIR/$tc" skip? && + atf_skip 'not compiled with history support' + local err_file="${SRCDIR}/${tc}.stderr" [ -f "${err_file}" ] && err_flag="-e file:${err_file}" local out_file="${SRCDIR}/${tc}.stdout"