I'm trying to use the ! (exclamation mark) to search my bash history on Mac and it doesn't work. Why doesn't MacOS have this feature and how can I install it?

It does work if I use zsh, FWIW. And !! to execute my last command also works. Here is my ~/.bash_profile:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.


export PATH=/usr/local/share/scala/bin:$PATH


export PATH

# Setting PATH for Python 3.5
# The orginal version is saved in .bash_profile.pysave
export PATH

# export VIRTUALENVWRAPPER_PYTHON="/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5"
# export WORKON_HOME=$HOME/.virtualenvs
# export PROJECT_HOME=$HOME/Devel
# source /Library/Frameworks/Python.framework/Versions/3.5/bin/virtualenvwrapper.sh
  • 3
    What exactly do you type and what the response from bash is? – Kamil Maciorowski Oct 21 '18 at 20:28
  • Say my last command was python3 script.py. Then I start typing !python3 scr and press tab. Nothing happens, except that the computer makes that sound it makes when you are trying to auto-complete something that doesn't exist. @KamilMaciorowski – ubadub Oct 21 '18 at 20:32
  • try set -H in bash and set +K in zsh – mosvy Oct 21 '18 at 20:45
  • also, "bang" expansion doesn't work in bash with Tab like in zsh. Try typing !py<escape>^ or bind some other key than M-^ to history-expand-line, example shift-Tab: bind '"\e[Z": history-expand-line'. – mosvy Oct 21 '18 at 21:06
  • 1
    run the bind ... command from my command above, set -H, then type !py and then press shift-Tab. still nothing? – mosvy Oct 21 '18 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.