What's the use of `!#` in bash?

Viewed 816

I'm not talking about the UNIX shebang meant to give the path of an interpreter. In fact, the shebang has made it quite hard to google this question successfully...

I'm talking about bash expansion:

  • !! retrieves the immediately preceding command (akin to the up arrow, but more usable)
  • !$ retrieves the last word of the last command
  • !# appears to retrieve the current line

But what're actually useful uses of !#?

  • echo !# expands to echo echo
  • echo echo !# expands to echo echo echo echo
  • ls !# expands to ls ls.

All of which seem overwhelmingly pointless. All I know about the !# command is what I've learned from using it – I'm not certain that I know its true functionality.

2 Answers
Related