Recently I typed at my terminal

username:~$ !!

and got error from bash:

bash: !!: command not found

At the same time, it succeeds when done under superuser.

I investigated my user's PATH's content and found nothing suspicious:


Here is output of:

username:~$ history | tail
1993  date
1994  cal
1995  vcal
1996  uptime
1997  uname
1998  uptime
1999  uname
2000  uptime
2001  uname
2002  history | tail


username:~$ echo foo
username:~$ !!
bash: !!: command not found
  • 2
    Does it always happen? What if you run echo foo and then !!? Also, please edit your question and add the output of history | tail or so. Does your shell session have any history? – terdon Nov 19 '16 at 11:44
  • 1
    What is your input language ? Are you using standard english or some other keyboard ? – Sergiy Kolodyazhnyy Nov 19 '16 at 11:53
  • 5
    Is histexpand set in your shell options? what is the output of echo $-? – steeldriver Nov 19 '16 at 14:29
  • 2
    @muru, ...speaking as a former freenode #bash regular, I used to spend a lot of time advising folks to disable it, without getting any pushback from other channel elders -- people being surprised by commands with ! literals not being honored without extra quoting was a much more common occurrence than finding someone who wanted history expansion functionality not available in easier-to-use form through readline. – Charles Duffy Nov 19 '16 at 20:01
  • 1
    @muru, I disabled it in the middle of my configuration file when was copying blindly .bashrc content from one of many example files I found on the internet. – Bulat M. Nov 20 '16 at 4:21

History expansion might be disabled:

$ echo foo
$ !!
echo foo
$ set +o histexpand
$ set -o | grep hist
histexpand      off
history         on
$ echo foo
$ !!
bash: !!: command not found

Try set -H or set -o histexpand.

  • @Serg set -o, or the special variable $- – muru Nov 19 '16 at 12:10
  • OK, I see, that's what you're doing with set -o | grep hist – Sergiy Kolodyazhnyy Nov 19 '16 at 12:12

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.