I'm somewhat new to shellscripting. I am attempting to make a shellscript that when exececuted, will execute the second to last and the last executed commands in my terminal in that order. If I go to my terminal and type !!
the last command will be executed. Similarly, if I type !-2
the second-to-last command will be executed. I am effectively trying to make a shellscript that when executed will perform the equivalent of me typing !-2
into my terminal twice in succession. I've tried numerous ideas (echo !-2
, !-2
, etc.) and honestly can't figure out how to get this to work. Can anyone give me any pointers?
Asked
Active
Viewed 60 times
0

supersmarty1234
- 101
tail
. The history file probably won't have whatever commands you've run in the current shell session, only whatever was most recently saved to it. – cas Feb 17 '22 at 09:46