I have a function that reads a text file containing a list of tests and returns an array with each line being a separate element in the array
the file contains:
existing_user_test
new_user_test "approved"
random_user_test
here is the code
test_list=( $(get_test_list $test_list_file) )
for i in ${!test_list[@]}; do echo ${test_list[$i]}; done
get_test_list() {
declare -a test_list
local test_file=$1
while IFS= read -r line; do
test_list+=("${line}")
done < $test_file
echo "${test_list[@]}" # return the test_list array
}
This works great for all tests that have no spaces in them
However when I loop over the test_list variable - it divides the test that has a space in it into 2 elements
so its outputting
existing_user_test
new_user_test
"approved"
random_user_test
instead of
existing_user_test
new_user_test "approved"
random_user_test