ru Русский

Reticularium

NETWORKS PLACE

Problem: in my script I need to do some operations on a list of files stored in a file. I can’t use the ‘while read’ loop because I do these operations on a variable that may or may not be a list of files depending on some condition.

Without variable there is a simple method, e.g.


cp {file1,file2,file3} /some/folder

but if I do something like


myvar="{file1,file2,file3}"; cp $myvar /some/folder

- this won’t work.

The solution is using an array:


myvar=( file1 file2 file3 ); cp ${myvar[*]} /some/folder

This works!

Comment it: