Expansion in an eval variable

78 views Asked by At

Is it possible to do expansion inside an eval variable?

Example:

$ eval VAR=`echo some/path/{file1,file2}`
bash: some/path/file2: No such file or directory

I expected the same result as without using eval, that is, setting variable VAR to some/path/file1 some/path/file2

1

There are 1 answers

2
myself600 On BEST ANSWER

Adding quotation marks solved the problem:

$ eval VAR=\"`echo some/path/{file1,file2}`\"

Background: I was trying to define a variable inside eval which contained multiple lines of commands written in a PKGBUILD script, but was advised against doing that. For an appropriate solution, see Using variables in bash function names.