Pressing "UP" for command history in `sh` is partially broken (for a while)

Sometime around FreeBSD 14 (I think) the default shell was changed to `sh`. In early beta versions of 14.0 it worked as you'd expect. Type in a few letters of the command, press the UP key on your keyboard and it would cycle through the history and complete the rest of the command with anything that started with those letters. Even just one or two letters.

Then when the final version was released that behavior broke. It became less reliable. No longer could you just type just one or two chars, and sometimes pressing up would do absolutely nothing of value except show you any command unrelated to what you typed in. It's been liked that ever since.

This was feature in csh, and it was one of (if not the reason) I fell in love with FreeBSD.

Why has it been broken for some long? How would I even fill a bug report for this?
 
Well if you change your shell back to csh it works again. It's just not a feature of sh.

edit: it seems sh has that feature too nowadays.
 
For me it does the job, mostly I would say, because I agree the feature is not as reliable as it is in other shell, a bit buggy sometimes but overall it works, maybe try with at least 3 letters instead of 2.
Also check your history file just to be sure that what you seek is indeed there.

Since that feature has been imported the shell feels more comfortable for my FreeBSD VMs. If I have to keep the VM around a bit longer then zsh will be installed no doubt, but for a quick test then the modern sh is good enough.
 
People say that [t]csh is the default shell, but it's only the default for root, the default in adduser is sh. Has the default for root really changed? Are you sure you aren't mixing-up the two cases?
 
Well if you change your shell back to csh it works again. It's just not a feature of sh.

edit: it seems sh has that feature too nowadays.
Right, it is a feature that was working correctly in a pre-release version of I think 14.0, but then broke down when the actual release candidates started showing up.

Just "changing my shell back to csh" isn't a solution. Sure it might fix my problem, but it still remains broken for everyone else.
I normally use fish anyway, but when managing hundreds of servers, I tend to use what the defaults are. The default shell is now sh.
 
. On a vm, d, it's 15.1-p2 upgraded, I think from a 15.0 install shortly after 15.0 was released. it came out. Root has a default shell of /bin/sh and the up arrow works as expected, that is, it repeats the previous command.
 
. On a vm, d, it's 15.1-p2 upgraded, I think from a 15.0 install shortly after 15.0 was released. it came out. Root has a default shell of /bin/sh and the up arrow works as expected, that is, it repeats the previous command.
It works sometimes. It's inconsistent. I'm reminded of this everyday each time I push the up arrow on my terminal. :)
 
I see that in sh - so up arrow repeats the previous command, but I thought we were talking about the nicer bit where if you typed the first letter and pressed up arrow it would show the previous command (in your history) starting with that letter? That's the bit that I'm missing.
 
I thought we were talking about the nicer bit where if you typed the first letter and pressed up arrow it would show the previous command (in your history) starting with that letter? That's the bit that I'm missing.
Yes, that's exactly the feature I am describing. It only works 'some of the time'. I haven't quite nailed down the pattern enough in order to write up a good bug report about it.

Say for example your history contains 'grep -i test example.txt'

It's basically hit or miss on what happens when you type in 'gre' and press up. It almost never works when you type 'g' or 'gr' when you press up.
It's even worse between sessions.
 
I haven't quite nailed down the pattern enough in order to write up a good bug report about it.
I don't think it is a bug. Its how it has always worked. It is why I change shell back to tcsh. csh requires more characters for completion than tcsh.

The users /home/.cshrc file sets the standard for both shells. It is the only thing that separates the two shells.
tcsh is symlinked to csh. But settings in user .cshrc dictate behavior.

Code:
       if ( $?tcsh ) then
                bindkey "^W" backward-delete-word
                bindkey -k up history-search-backward
                bindkey -k down history-search-forward
        endif
 
I see that in sh - so up arrow repeats the previous command, but I thought we were talking about the nicer bit where if you typed the first letter and pressed up arrow it would show the previous command (in your history) starting with that letter? That's the bit that I'm missing.
Isn't that the ed-search-prev-history part in .shrc ?

 
It works sometimes. It's inconsistent. I'm reminded of this everyday each time I push the up arrow on my terminal.
It seems, it uses regexp, and hence searches for sub-expresion anywhere in the each command of history.

Just type ^ at the beginning of what you want to search. For example ^pw if you want pwd from history.
 
Isn't that the ed-search-prev-history part in .shrc ?
I'm not sure - this is just about muscle memory - I'm so used to typing the first letter of the previous command I want to use and pressing up arrow and bingo there is what I want. If I wanted the second-previous mysql command, type m and push up arrow twice.

I do not know if this is a bug or just something sh does differently. Chiming in to let the OP know he's not the only one who has noticed.

You get so used to things working a certain way e.g. Alt-Tab for switching between windows - and then it gets changed - a bit of a wrench. (I'm not saying anyone is changing Alt-Tab, just that is the same level of auto-pilot as type-a-letter-press-up for me).
 
Is it really broken? I don't notice it at all. I've upgraded from 13.x all the way to 15.2 and it has always worked reliably...

But I wonder if that could possibly be because I use
Code:
set -o vi
and use j and k keys instead of up, down keys.
 
Back
Top