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?
"${omd_site_paths[@]}". Moreover, the entire thing is not safe at all against whitespaces and special characters in paths.find -print0and awhile readloop. See BashFAQ/001: mywiki.wooledge.org/BashFAQ/… . Carefully replicate all the options to both commands! They are all vital in ensuring robustness.