Bash Cleverness - Too Clever by 0.5?
I recently saw !$:t
in a tar
command and had no idea what it was doing:
|
|
In line two, !$
selects the previous command, courtesy of command history expansion, and then :t
gets the final section of that command (so, in this case, we end up with downloadable-file.tar.gz
).
The man page for the history command refers to :t
as follows:
Remove all leading file name components, leaving the tail.
(Which reminds me of the basename
and dirname
commands.)
I saw the above example here - where additional dexterity is used.
I admire the conciseness, but would prefer explicitness, in this case.
Author northCoder
LastMod 06-Apr-2020