0

Could somebody explain this output?

$ echo !
!
$ echo !!
echo echo !
echo !
$

I expected sedond echo to write only !!

  • If you view your command history & decide you want to run command 419 in that history, you can type !419 and it'll execute. Provided answers tell you !! executes your last command, but it has other uses too :) – guiverc Feb 18 '19 at 22:47
  • Same question, although different context: askubuntu.com/q/627781/295286 Effectively duplicate – Sergiy Kolodyazhnyy Feb 18 '19 at 23:30
  • 3
    To prevent the !! from being evaluated (it's being evaluated prior to executing the echo cmd), use quotes, eg echo '!!' gnu.org/software/bash/manual/html_node/Quoting.html – michael Feb 18 '19 at 23:33
2

!! means last command.

echo !! will echo last command, which was echo !.

1

Easily explained:

$ echo 1
1
$ !!
echo 1
1

so !! just repeats the last command, so

echo !!

does excactly what it's supposed to to!

;-)

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