2

I was playing with string substitution while learning a bit more of bash, and I have add !! into some dummy example echo ${TEST/hey/!!}...

I was surprised that !! was replaced with last entered command... what is it? is it somehow connected to magick codes link $? or $_ or even -. Is there anything else I can use in same manner in bash?

1 Answers1

1

Bash performs different kinds of automatic replacements called expansions. For example, some of them are:

  • History Expansion
  • Path Expansion
  • Parameter Expansion
  • and others...

When you include !! bash automatically replaces by previous executed command. The character ! performs history expansion. For example !10 is replaced by the 10th command in the command history. $ does parameter and variable expansion. All of those characters: -, _, and ? are special parameter for bash.

The best source to learn about it is the bash manual: Bash Reference Manual: Top

The example you mention echo ${TEST/hey/!!} include both parameter and history expansions.

sebelk
  • 4,389