For example, I would like to do the following:
mv xxxx xxxx.bak
I know I could use the following instead:
mv xxxx{,.bak}
which I think is not direct somehow. It would be wonderful if I can do this like:
mv xxxx $1.bak
And sometimes we'll need it like this:
echo xxxx yyyy $1.suffix
I know we can refer to arguments of the previous command using "!:n", can I instead refer to arguments of the current command likewise?
BTW, I want to do it directly in shell(interactively). Thanks.
The current command line is referenced with !#
.
mv xxxx !#:1.bak
I recommend enabling the histverify
option if you aren't already using it, so you have a chance to proofread or edit the results of the history expansion before actually executing it. To do so:
shopt -s histverify
Or, if you don't want to enable that option and just want to verify a single command, use the :p
modifier to print the expansion instead of executing it:
$ mv xxx !#:1:p.bak
mv xxx xxx.bak
$
one way is to use a variable for this. simply like :
f="file"
cp $f $f.bak
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With