I'm trying to build a list of directories to exclude from a find command. Unfortunately sone of the directories have spaces in them. For example, suppose I have a list myList
of three directories, the second of which is called "b c"
/bin/bash
myList="a \\
b c \\
d"
I'm unable to convince 'bash` not to break up the second line into two individual tokens.
for example, this code
dirList=
stringArray=($myList)
for i in "${stringArray[@]}" ; do
dirList="$dirList -name $i -prune -o"
echo "$dirList"
echo " "
done
returns this:
-name a -prune -o
-name a -prune -o -name b -prune -o
-name a -prune -o -name b -prune -o -name c -prune -o
-name a -prune -o -name b -prune -o -name c -prune -o -name d -prune -o
But I want it to return
-name a -prune -o
-name a -prune -o -name b c -prune -o
-name a -prune -o -name b c -prune -o -name d -prune -o
The obvious way to deal with the space is to define the second line as "b c"
But then I have nested double quotes. I've tried (I believe) all of the suggestions on the web about dealing with nested quotes, but none are working for m. Could somebody please advise how to do this?