0

I'm new to BASH commands and I'm following some video lectures. Could anyone tell me why ^ln^stat gets "translated" into stat file.txt link_hard.txt ? The same happens with ^stat^ls -l^ that becomes ls -l file.txt link_hard.txt(see pic)

file.txt is an empty file and link_hard.txt is an hard link to file.txt.

https://i.stack.imgur.com/LPMEn.jpg

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Sciadi
  • 11
  • 1
  • See https://unix.stackexchange.com/questions/243317/bash-how-can-i-replace-a-string-in-a-previous-command – Felix Kling Sep 30 '21 at 09:10
  • 1
    It's [history expansion](https://www.gnu.org/software/bash/manual/bash.html#History-Interaction) to replace the first instance of a string in the previous command with another string; a shorthand for `!!:s^string1^string2^`. – Benjamin W. Sep 30 '21 at 09:13
  • Notice that it just replaces the first instance. use `!:gs/string1/string2` to replace all instances. – Benjamin W. Sep 30 '21 at 09:17
  • https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557 – William Pursell Sep 30 '21 at 09:21
  • Related: https://stackoverflow.com/q/2149482/3266847 and https://stackoverflow.com/q/649070/3266847 (but not exact duplicates - they know about `^`, but ask about something that substitutes all occurrences). – Benjamin W. Sep 30 '21 at 09:27

0 Answers0