Portable (cartesian) brace expansion in your shell
5 points by mqudsi
5 points by mqudsi
This doesn't work at all, and neither is a proper cartesian product of two sets...
Hm, it works for me (as long as there are no spaces or newlines in filenames)
touch /tmp/{hello,world,"hello world"}
ls $(printf '/tmp/%s\n' "hello" "world" "hello world")
ls: cannot access 'world': No such file or directory
/tmp/hello /tmp/hello /tmp/world
Using \n in the printf doesn't really help, and quoting either + it would not pass shellcheck.
but a funny workaround nevertheless
use
echoinstead ofprintfif your$IFSconfiguration splits on spaces
Isn't IFS only for loops? Oh no it isn't. I never touch IFS :D but TIL. Wild.
IFS=:
ls $(printf '/tmp/%s:' "hello" "world" "hello world")
/tmp/hello '/tmp/hello world' /tmp/world
Bash at least also supports empty values in the expansion. I use it all the time to create backups with mv file{,.old}.
I’d like to try {mkdir,chown,chmod} /var/log/{foo,bar,baz}