1
IFS='\n'
for i in "$(IFS='\n' printf 'abc\nxyz\n123 456\n')"; do
    echo "????"
    echo "$i"
done

echo "output"
echo "${args[@]}"

The following outputs:

????
abc
xyz
123 456
output

How can I get the for loop to iterate for each line? Why is the IFS='\n' command not making it behave in this manner?

1 Answer 1

3

The double quotes make the "command substitution" one single argument. Try without:

$ for i in $( printf 'abc\nxyz\n123 456\n'); do   echo "????";   echo "$i"; done
????
abc
????
xyz
????
123 456

Plus, your IFS is set to a string containing the two chars "\" and "n". In e.g. bash, you might want to try $'\n'.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.