简体   繁体   中英

Rhyme or reason to history buffer in Windows command interpreter?

When I am in a shell like bash, if I use the up arrow to go through the command-line-history buffer, it behaves in a predictable way: hitting up goes to the command I executed most recently.

In the Windows cmd.exe ("DOS") shell, sometimes hitting the up arrow goes to the most recent command, sometimes it goes to the 2nd most recent command or even the 3rd most recent command. Sometimes, to get to the most recent command I entered, I actually have to hit the down arrow! Sometimes I have to hit the down arrow twice !

What is the logic to this? It's been driving me batty for a long time.

The command selected by up/down-arrow is relative to the last-selected repeat.

So if you have executed

line 1
line 2
line 3
line 4

Then pressing up-arrow 3 times and enter would reselect and execute line 2

From there, you can down-arrow once to re-select line 3 or twice for line 4 or up-arrow once for line 2 , twice for line 1

BUT the new lines executed are appended to the list and if you enter a line manually, the selector moves to the bottom of the list again.

The line will not be entered into the list if it is a duplicate of the last entry, so you can up-arrow-and-execute a thousand times if you want to and up-arrow-twice will get the (-1001st) command entered.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM