0
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?

2

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'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.