I have a multiline string and I want to split is based on \n
for which I'm setting IFS=$'\n'
but it's not working, I've also tried IFS=
and IFS="
"
but no luck.
Below is the sample code
IFS=$'\n' read -ra arr <<< "line1\nline2\nline3"
printf "%s\n" "${arr[@]}"
# it only generates array of length 1
I'm using Ubuntu
with bash version being
GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Can someone point out the obvious.