I would like to perform command substitution before brace expansion, but couldn't:
$ ls {$(seq -s , 13 20)}.pdf
ls: cannot access {13,14,15,16,17,18,19,20}.pdf: No such file or directory
How can I do it?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityI would like to perform command substitution before brace expansion, but couldn't:
$ ls {$(seq -s , 13 20)}.pdf
ls: cannot access {13,14,15,16,17,18,19,20}.pdf: No such file or directory
How can I do it?
You simply need to use the eval
shell builtin:
$ eval ls {$(seq -s , 13 20)}.pdf
Where eval
takes the arguments passed to it:
ls {$(seq -s , 13 20)}.pdf
and concatenates them together into a single command:
ls {13,14,15,16,17,18,19,20}.pdf
which is then read and executed by the shell.
$ eval ls {$(seq -s , 13 20)}.pdf
13.pdf 14.pdf 15.pdf 16.pdf 17.pdf 18.pdf 19.pdf 20.pdf
have you tried
ls $(seq -f %.0f.pdf 13 20 )
-f
gives the format string.0f
for 0 decimal digit float.pdf
obvious (and you know about $( ) syntax)