I need to store a string that may include special characters (to be exact: *) into an array as individual strings. The string is returned by a function so at the point of the array declaration I do not know its contents
foo(){
in="my * string"
echo "$in"
}
arr=($(foo))
What I've already tried was:
arr=("$(foo)")
where * doesn't get expanded but the array consists of 1 string, and:
arr=($(foo | sed -r "s/[\*]/'*'/g"))
that replaces each occurence of * with the string: *. Which is not what I want to achieve. What I aim for is just storing each * from the returned string as *.
arr=("$(foo)"). Quoting the parentheses prevents this from being an array assignment.array=("my" "*" "string")in the end?