on-internet
← Community

Double quotes vs asterisk filename expansion in Bash

Stack Overflow ·

In the directories ~/temp/a/foo/ and ~/temp/b/foo foo/ I have some files named bar1, bar2, bar bar1, bar bar2, etc. I am trying to write a line of Bash that copies all these files in a directory containing "foo" as last part of the name to the folder above the respective "foo" folder. As long as there are no spaces in the file names, this is an easy task, but the two following commands fail when dealing with the foo foo directory: for dir in `find . -type d -name '*foo'` ; do cp $dir/* "$(echo $dir|sed 's_foo__g')" ; done (The cp command fails to see the last foo of "foo foo" as part of the sa

Comments

Sign in or sign up to comment and upvote.

No comments yet.