Bash – Can we use two brace expansions together

bashshell

For example, I want to rename a file abc to bd.

Why do the two brace expansions seem not to work?

Consider the following example.

$ touch abc
$ mv {a,}b{c,d}
mv: target `bd' is not a directory

How shall I make brace expansion work?

Best Answer

Two brace expansions do work, they just don't work the way you want them to:

$ touch abc
$ mv {a,}b{c,d}
mv: target `bd' is not a directory
$ echo mv {a,}b{c,d}
mv abc abd bc bd

They are expanded separately - effectively the first one is expanded, leaving you with mv ab{c,d} b{c,d} and then the second is expanded, leaving you with mv abc abd bc bd.

Related Question