Thursday, 15 September 2011

bash - How to copy multiple files from a different directory using cp, variable and brackets? -



bash - How to copy multiple files from a different directory using cp, variable and brackets? -

my question similar how re-create multiple files different directory using cp?

i don't want utilize explicit loop. here do:

$ files_tools="fastboot,fastboot-hw.sh" $ cp $home/tools/{$files_tools} $top_dir/removeme cp: cannot stat `/home/johndoe/tools/{fastboot,fastboot-hw.sh}': no such file or directory

the files nowadays , destination valid, because:

$ cp $home/tools/{fastboot,fastboot-hw.sh} $top_dir/removeme $ echo $? 0 i tried remove double quote files_tools, no luck. i tried quote , double quote {...}, no luck i tried backslash brackets, no luck i guess problem of when shell expansion occurs.

this reply limited bash.

prepend echo see cp command turns into:

echo cp $home/tools/{$files_tools} $top_dir/removeme

you have insert eval within sub-shell create work:

cp $( eval echo $home/tools/{$files_tools} ) $top_dir/removeme

bash

No comments:

Post a Comment