Dialog , capture multiples inputs in variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Dialog , capture multiples inputs in variables
# 1  
Old 12-04-2016
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 :
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

Code:
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 :
Code:
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 .


Moderator's Comments:
Mod Comment Please use code tags, not quote tags around snippets of code and data


---------- 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 :

Code:
#!/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 :

Code:
#!/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

Last edited by pedropt; 12-05-2016 at 09:29 AM.. Reason: quote tags -> code tags
This User Gave Thanks to pedropt For This Post:
# 2  
Old 12-04-2016
Thank you for your solution and adding to the knowledge base...

Bazza.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

TCL script to capture range of lines and create two independent variables

Hi I am having a code as stated below module abcd( a , b , c ,da , fa, na , ta , ma , ra , ta, la , pa ); input a , b, da ,fa , na , ta , ma; output c , ra ,ta , la ,pa ; wire a , b , da , fa ,na , ta , ma; // MBIST Structures... (1 Reply)
Discussion started by: kshitij
1 Replies

2. Shell Programming and Scripting

Not able to capture error while using dialog

I am not able to capture errors while I am using dialog. For example: dialog --gauge "Verifying file..." 10 75 < <( while read LINE do hash=$(echo $LINE | cut -f1 -d' ') directory=$(echo $LINE | cut -c 34-) PCT=$(( 100*(++i)/n )) echo $PCT md5deep -a $hash $directory >... (3 Replies)
Discussion started by: yamanoorsai
3 Replies

3. Shell Programming and Scripting

awk on multiples files

Ques from newbie I want to total column X from large number of files, and view totals for each file separately with the filename. I have tried: for i in `ls -1 *.pattern`; do cat "$i" | awk '{SUM += $4} END { printf("%8d\t%8d\n", $i,SUM) }'; done does not work. appreciate your help (5 Replies)
Discussion started by: analyst
5 Replies

4. Programming

multiples of 10 in java

Hi Guys, I wonder how can I determine when a given number is a multiple of another one in java. Let's say if I have 27 how can I determine whether is multiple of 5 using java programming. Thanks. (1 Reply)
Discussion started by: arizah
1 Replies

5. Shell Programming and Scripting

join multiples seds

Hi I have this string with 3 seds.. cat /tmp/roletmp|sed "s/$role2del//" | sed "s/,,/,/" |sed "s/^,//" |sed 's/,$//' How can I join these 3 seds in one? regards Israel. (3 Replies)
Discussion started by: iga3725
3 Replies

6. Shell Programming and Scripting

multiples menu in ksh

Hi, IS possible in ksh to make multiples menus? For example: My menu. 1)Option1 1.1)Option1.1 2.3)Option1.2 2)Option2 2.1)Option2.1 . . . x)Exit I've tried with case but no success. Thanks in advance. (3 Replies)
Discussion started by: iga3725
3 Replies

7. Programming

Pointer addresses in multiples of 32 ?

1. Why are the pointers' addresses every 32 ? 2. Am I correct in stating that memset is writing to memory that is not allocated to any of the 3 pointers ? Is it writing to memory in between the pointers ? 3. Are the 3 pointers contiguous in memory ? 4. I only allocated 10 bytes for each pointer.... (5 Replies)
Discussion started by: cyler
5 Replies

8. UNIX for Dummies Questions & Answers

Using cp for copying multiples files

Hi all, I've got this question about using cp for copying multiples files from the same source directory to another directory, considering that my working directory ain't the same of the source directory. Let me give you a simple example what I'm talking about: Suppose the following files... (2 Replies)
Discussion started by: chapeupreto
2 Replies

9. Shell Programming and Scripting

Unix / Linux Dialog Utility - how to open 2+ more dialog windows ?

Hi, example of Unix / Linux dialog utility is below. I am going to use dialog as simple GUI for testing of a modem. So I need to combine some dialog boxes into one. I need to have input box, output box, info box, dialog box, radiobox as in any standard program with graphical user... (2 Replies)
Discussion started by: jack2
2 Replies

10. Shell Programming and Scripting

KSH Setting multiples variables with an array

ih all, info=$(get_Info $daemon) # $info give : # "ev20 8800 TTIOGC 12345 astos EDITEUR 0 0 . ." server=$(echo $info | cut -d" " -f1) port=$(echo $info | cut -d" " -f2) dname=$(echo $info | cut -d" " -f3) dport=$(echo... (1 Reply)
Discussion started by: wolfhurt
1 Replies
Login or Register to Ask a Question