Bash Shell Scripting – Dialog form variables

bashscriptingshellvariables

So, I just took up Shell Scripting and I'm developing an address book.

For the user to insert a contact I made this form:

form=$(dialog                                      \
    --title "INSERIR"                              \
    --form  ""                                     \
    0 0 0                                          \
    "Nome:"      1 1    "$nome"     1 10 20 0      \
    "Morada:"    2 1    "$morada"   2 10 20 0      \
    "Telefone:"  3 1    "$telefone"     3 10 20 0  \
    "E-Mail:"    4 1    "$mail"     4 10 20 0      \  
2>&1 1>&3)

And I want to insert those values through a MySQL query. I saw somewhere that I had to use, for instance:

form[$1]

In order to access the variable $nome. However, it was a comment from 2008.
What is the easiest way to access those variables?

Thank you!

Best Solution

IFS=$'\n' read -r -d '' nome morada telefone mail < <( dialog ... )

Unlike dialog ... | { read; ... } (which scopes the variables which are read to a subshell), this approach puts dialog in the subshell, and your variables in the main shell -- much more convenient.