1

Recently, I noticed that echos in which I include lots of "!" result in weird stuff. For example: echo !! gives me:

echo rm -r * 1000
rm -r * 1000

(rm -r * was the last command I executed before typing it). Why is this happening, and is there a way to disable it?

user96931
  • 461

1 Answers1

3

You ran into shell expansion - the shell will parse your command and replace a special wildcards with other information. Try echo '!!' (single quotes) to understand what shell expansion and quoting can do.

You can read more about shell expansion in the man page for bash. Note the sections for history expansion, which discusses event designators like !!, and expansion, which discusses other forms of shell expansion. The section on quoting explains the behavior of bash's quoting mechanisms and the difference between how single and double quoted strings are evaluated.

gnubeard
  • 1,274
Eugen Rieck
  • 20,637