What's the point! #: *! #: 1- in bash command?
It uses bash's history replacement mechanism .
Specifically, it !#
refers to the current line (before, but not including the location itself !#
). !#:*
is the part of this line after the command name (so, in this case, "This is a sentence."
). !#:1-
matches with !#:*
, except that it omits the last word (so it doesn't include the second copy "This is a sentence"
we just added via !#:*
).
The end result is a string with three copies This is a sentence.
, selected into a file named text3
.
source to share
Exit from:
echo "hello" !#
is equivalent to output:
echo "hello" echo "hello"
which the:
hello echo hello
!#
means replacing the previous line before !#
again with the current line (shortcut to avoid writing again)
0th 1st 2nd 3rd
-------- ------- ------ --------
echo "hello" echo "hello"
-------- ------- ------ -------
!#:0
means the replacement value in the 0th column
!#:1
means the replacement value in the 1st column
Example
echo "hello" !#:1
The output is the same as the output:
echo "hello" "hello"
which the:
hello hello
!#:1
is replaced with the row in the 1st column - "hello"
echo "hello" !#:0
produces the same result as:
echo "hello" echo
which the:
hello echo
!#:0
is replaced with the string in the 0th column - echo
source to share