Is there a way for Bash to return the first word of the previous command (the command name itself), similar to how
You can choose a word by number with
!:. This includes any pre-command assignments, so the exact number you need varies.
$ x=3 some_command foo # some_command is !:1 $ ls -l # ls is !:0 $ x=6 y=3 bar # bar is !:2