Often I'm writing a command in a bash prompt, where I want to get previous arguments, in the CURRENT line I'm typing out, and put in other places in the command.
A simple example, would be if I want to rename a file. I would
- type out the
mv
command - type the filename I want to move,
~/myTestFileWithLongFilename.txt
- now I want to just change the extension of the file that I supplied in the first argument, without typing it again.
Can I use history or bash completion in some way to autocomplete that first argument?
$ mv ~/myTestFileWithLongFilename.txt ~/myTestFileWithLongFilename.md
I know of course I could execute the incomplete command, to get it into the history, and then reference it with !$
, but then my history is polluted with invalid commands, and I'm wondering if there's a better way
mv
command, but something else) – Brad Parks Mar 24 '21 at 18:54