Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of !#:* !#:1- in a bash command?

Tags:

linux

bash

In the following Bash command, what is the meaning of: !#:* !#:1

echo "This is a sentence." !#:* !#:1- >text3
like image 477
Adalid_Negro Avatar asked Dec 08 '22 06:12

Adalid_Negro


1 Answers

It's using bash's history substitution mechanism.

Specifically, !# refers to the current line (up to but not including the location of the !# itself). !#:* is the part of that line after the command name (so, in this case, "This is a sentence."). !#:1- is the same as !#:* except that it omits the last word (so it doesn't include the second copy of "This is a sentence" that we just added via the !#:*).

The end result is a line with three copies of This is a sentence. echoed into a file named text3.

like image 90
Mark Reed Avatar answered Dec 11 '22 09:12

Mark Reed