0

in this code i just save paths into array#1. This array works fine:

echo "Searching for *omd*-paths..."
cd /

# creating array#1
all_omd_paths=`find -type d -name omd`

Ok, but now i want to put specific paths into another array (array#2):

for path in $all_omd_paths
do
        if [[ $path == *"s"* ]]; then
            # fill array#2
            omd_sites_paths+=($path)
        fi
done

for path in $omd_sites_paths
do
    # wrong output
    echo $path
done

With the second for-loop i just get ONE path on output... But i know there are more saved in array#1. What s wrong with array#2? How do i fill it correctly?

3
  • 2
    Your creating array#1 is downright wrong. It doesn't create an array. And when accessing all array elements in bash, you need "${omd_site_paths[@]}". Moreover, the entire thing is not safe at all against whitespaces and special characters in paths. Commented Dec 4, 2015 at 9:45
  • Oh ok, thank you. Do you have a hint or keyword for getting the paths out of 'find'-command? Commented Dec 4, 2015 at 10:05
  • 1
    Use find -print0 and a while read loop. See BashFAQ/001: mywiki.wooledge.org/BashFAQ/… . Carefully replicate all the options to both commands! They are all vital in ensuring robustness. Commented Dec 4, 2015 at 10:08

1 Answer 1

1

If $omd_sites_paths is an array:

for path in ${omd_sites_paths[@]}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.