On Wed, Oct 26, 2022 at 11:30:20AM +0200, Uwe Werler wrote: > Hi all, > > when running ksh in vi-mode an empty line could be stored in history: > > Steps to reproduce in command mode: > > 1. go history back e.g.: k > 2. start editor with: v > 3. delete the whole line and :wq > 4. check history with fc -l
Doing this in bash prints an empty command as expected but then adds the command that was :wq'ed and NOT executed to the history, which seems like a bug. > Without patch: > > zarathustra:/usr/src/bin/ksh$ fc -l > 2 ls -la > 3 fc -l > 4 > > With patch: > > zarathustra:/usr/src/bin/ksh_new$ fc -l > 7 fc -l > 8 ls -la > 9 fc -l > 10 ls -la Makes sense to me, works, keeps regress happy. Either way, knowing what other shells do is nice, but this example is nothing I'd deliberately keep in sync with others -- bash seems weird here anyway and your diff seems like an improvement to me. Maybe someone else can come up with a useful case for empty lines in history? ... or an OK? > Index: history.c > =================================================================== > RCS file: /cvs/src/bin/ksh/history.c,v > retrieving revision 1.84 > diff -u -p -u -r1.84 history.c > --- history.c 27 Oct 2019 15:02:19 -0000 1.84 > +++ history.c 26 Oct 2022 08:02:52 -0000 > @@ -659,6 +659,9 @@ histsave(int lno, const char *cmd, int d > if (ignorespace && cmd[0] == ' ') > return; > > + if (strlen(cmd) == 0) > + return; > + > c = str_save(cmd, APERM); > if ((cp = strrchr(c, '\n')) != NULL) > *cp = '\0'; > -- > > With kind regards / Með bestu kveðju / Mit freundlichen Grüßen > > Uwe Werler >
