Dialog , capture multiples inputs in variables

Hi everyone , i am trying to do a shell script with dialog , but i have a problem capturing each input variable to then use "echo" to write those inputs on specific orders in a file .

If i use this code :

dialog --backtitle "Dialog Form Example" --title "Dialog - Form" \
--form "\nDialog Sample Label and Values" 25 60 16 \
"Input A:" 1 1 "Value 1" 1 25 25 30 \
"Input B:" 2 1 "Value 2" 2 25 25 30 \
"Input C:" 3 1 "Value 3" 3 25 25 30 \
"Input D:" 4 1 "Value 4" 4 25 25 30 \
2>/test

what will happen is that the values from each input will be written on test file each one on each line .
And i want to retrieve each input value to use with "echo"
like

echo $var1 $var2 $var3 $var4 >> /test 

Using "echo" i can write all variables in one single line and add extra data to the line if i want , like this next example :

echo $var1,$var2,$var3,$var4 >> /test 

Anyone have an idea how to push dialog variables ?

The script i have here is working like i want with "read" command , but i want to make it graphical with dialog but i have no clue how to get what i need .

---------- Post updated at 03:03 PM ---------- Previous update was at 10:55 AM ----------

I was going around on the web looking for pieces of code , so , i got how this must be done properly , here it is the solution for this issue .
dialog must create a single temp file for each input , and then "cat" must be use to read each input in those files , create a variable for each one in memory and then you can use "echo" to write those variables in some unique file .
After cat reads each variable you must delete the temporary files used for the imputs .

The script is something like this :

#!/bin/bash
dialog --backtitle "Dialog Form Example" --title "Dialog - Form" \
--form "\nDialog Sample Label and Values" 25 60 16 \
"Form Label 1:" 1 1 "Value 1" 1 25 25 30 > /tmp/inputa.$$ \
"Form Label 2:" 2 1 "Value 2" 2 25 25 30 > /tmp/inputb.$$ \
"Form Label 3:" 3 1 "Value 3" 3 25 25 30 > /tmp/inputc.$$ \
"Form Label 4:" 4 1 "Value 4" 4 25 25 30 > /tmp/inputd.$$ \
2>&1 >/dev/tty
# Start retrieving each value from each input to a specific variable
retval=$?
input1=`cat /tmp/inputa.$$`
input2=`cat /tmp/inputb.$$`
input3=`cat /tmp/inputc.$$`
input4=`cat /tmp/inputd.$$`
# remove temporary files created
rm -f /tmp/input*.$$
echo $input1 $input2 $input3 $input4 >> testfile

Last Update :
The previous code will put your variables on a single line , bu i wanted to add extra data to "echo" command and i had issues doing that on 1 line only .
So , i had to use a different approach on the subject , i had to create a single file for all outputs and then use "sed" to read each line 1 by 1 and declare that data on variables to be able to do what i needed .

Basically there are some changes on the code , and i also am posting it here for my future consult and for others with same issue :

#!/bin/bash
dialog --backtitle "Dialog Form Example" --title "Dialog - Form" \
--form "\nDialog Sample Label and Values" 25 60 16 \
"Form Label 1:" 1 1 "Value 1" 1 25 25 30  \
"Form Label 2:" 2 1 "Value 2" 2 25 25 30  \
"Form Label 3:" 3 1 "Value 3" 3 25 25 30  \
"Form Label 4:" 4 1 "Value 4" 4 25 25 30 > /tmp/out.tmp \
2>&1 >/dev/tty
# Start retrieving each line from temp file 1 by one with sed and declare variables as inputs
input1=`sed -n 1p /tmp/out.tmp`
input2=`sed -n 2p /tmp/out.tmp`
input3=`sed -n 3p /tmp/out.tmp`
input4=`sed -n 4p /tmp/out.tmp`
# remove temporary file created
rm -f /tmp/out.tmp
#Write to output file the result
echo $input1 , $input2 , $input3 , $input4 >> testfile

If
input 1 = ab
input 2= cd
input 3=ef
input 4=gh

then the output of this code written on testfile will be :
ab,cd,ef,gh

1 Like

Thank you for your solution and adding to the knowledge base...

Bazza.