This is a technique I use often:
mv file.name{,.bak}
cp process.log{,.old}
etc. mv file.name{,.bak}
cp process.log{,.old}
etc. mv file.name !#:1.bak
cp process.log !#:1.old
!#:1 expands to the word with index 1. $ echo foobar !#:1:s/foo/bar
echo foobar barbar
foobar barbarand i always use ctrl-alt-e to expand and check even if i dont want to edit
mv file file.bak; mv file.new file
Nested {} can handle that one, cutting four 'file's down to one: eval mv file{,{.bak\;mv\ ,.new},}
Anyone have a way to hack that to cut the two 'mv's down to one? $ printf '[%s]' file{,{.bak\;mv,.new},}
[file][file.bak;mv][file.new][file]
(Note: I took out the '\ ' from the original because I realized it is not necessary).The eval is there because in bash text expansion occurs after ';' is interpreted, and we need that to be the other way around. Hence, the escaping of ';' in the input to preserve it for text expansion, and then the eval afterward to get ';' interpreted.
I jumped at it because there are other things one might like to achieve with brace expansion but turn out to be impossible because it is evaluated first - you can't use them with variables.
Yup:
mv -bS .bak file{.new,}
Should give the same result if you're using gnu coreutils 'mv', though it's obviously not as generally useful as nested braces.