dylan12345 dylan12345 - 1 year ago 117
Bash Question

Bash !$ equivalent for first word

Is there a way for Bash to return the first word of the previous command (the command name itself), similar to how

returns the last word of the previous command?

For instance:

ls -l

I would like to return

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download