Double quotes do NOT preserve the newline character in shell script // Zenity

234 Views Asked by At

I use Tokland's youtube-upload to upload videos. I feed my script which does the upload with data that I copy+paste from a form textarea field into a zenity dialog (like title, description, etc.). That input gets split into single items. That all works well, except for the description, which is cut off after the first newline.

When I isolate the description with a single dialog, it works

description=$(zenity --entry --text "FEED ME" --title "Description" --entry-text="");
printf $description # print outs the description with newlines

Now I try it with a zenity --forms dialog, but again the description is cutoff.

unset IFS

multiInput=$(zenity --forms --title="Everything + Description" --text="ENTER DATA  \
    --add-entry="Everything" \
    --add-entry="Description");

printf "%s\n" "$multiInput" # prints out form input properly w/ linebreaks

IFS="$IFS|" read -ra ALLdesc <<< "$multiInput"

printf "${ALLdesc[1]}" # prints out only the first line

I read that enclosing a variable in "" should prevent this, but that does not work here. Any idea about this?

Thanks, SV

1

There are 1 best solutions below

9
On

By setting IFS='|' you are saying you want word splitting on the | character only.

Since you want to also retain newlines, you'll have to ensure \n is in the IFS as well. So, you should append | to IFS rather than overwriting it, e.g. IFS="$IFS|".