While in a Linux shell I have a string which has the following contents:
cat
dog
bird
and I want to pass each item as an argument to another fu
Just pass your string to your function:
function my_function
{
while test $# -gt 0
do
echo "do something with $1"
shift
done
}
my_string="cat
dog
bird"
my_function $my_string
gives you:
do something with cat
do something with dog
do something with bird
And if you really care about other whitespaces being taken as argument separators, first set your IFS
:
IFS="
"
my_string="cat and kittens
dog
bird"
my_function $my_string
to get:
do something with cat and kittens
do something with dog
do something with bird
Do not forget to unset IFS
after that.