2

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

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?

3 Answers 3

2

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
1
  • The first command cut off a lot of paths in the output but the zsh command worked perfectly! Thank you so much! Commented Sep 3, 2010 at 7:26
2

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.

1
  • 1
    Add -print0 to the find command, and specify -0 to xargs
    – Not Sure
    Commented Jun 5, 2011 at 22:39
1

I think that you are complicating everything.

Maybe you only need this:

find $(pwd) -type d | sed 's/ /\\ /g'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .