Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm working on a script and I'm stuck, even with the help of teh googles.

Here's my code:

for FOLDER in `find . -type d | sed "s#^.#$(pwd)#" | sed 's/ /\ /g'`
do
    echo "$FOLDER"
done

This will replace only the first instance of " " with "\ " but not the rest.

Any ideas?

share|improve this question
add comment

3 Answers 3

up vote 3 down vote accepted

Forget about structuring your command that way and use find -execdir instead:

find . -type d -execdir sh -c 'pwd' \;

Or use zsh:

for d in **/*(/); do
  echo $d
done
share|improve this answer
    
The first command cut off a lot of paths in the output but the zsh command worked perfectly! Thank you so much! –  MonkeyWrench32 Sep 3 '10 at 7:26
add comment

You can use xargs instead of a loop for executing the same command on a list of elements. There are options to take care of whitespaces.

share|improve this answer
1  
Add -print0 to the find command, and specify -0 to xargs –  Not Sure Jun 5 '11 at 22:39
add comment

I think that you are complicating everything.

Maybe you only need this:

find $(pwd) -type d | sed 's/ /\\ /g'
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.