bash对话框从窗体读取变量

bash对话框从窗体读取变量,bash,dialog,Bash,Dialog,假设我得到了如下定义的对话框: 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

假设我得到了如下定义的对话框:

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
这将显示4个输入。。。但是我如何在bash脚本中读取它的输出呢


$?
似乎输出
0

您需要将对话框的标准输出重定向到一个变量:

RESULTS=$(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)
这样,所有的值都将存在


当您想要将不同的表单字段分配给不同的var时,您需要解析输出

ans=$(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 2>&1 >/dev/tty)
echo -e "\n\n\n\nAnswer=[${ans}]"
i=0
while read -r line; do
   ((i++))
   declare var$i="${line}"
done <<< "${ans}"
echo "var2=${var2}"
ans=$(dialog--backtitle“dialog-Form示例”--title“dialog-Form”\
--表格“\n模拟样品标签和值”25 60 16\
“表格标签1:“1 1”值1“1 25 25 30”\
“表格标签2:“2 1”值2“2 25 25 30”\
“表格标签3:“3 1”值3“3 25 25 30”\
“表单标签4:“4 1”值4“4 25 25 30 2>&1>/dev/tty)
echo-e“\n\n\nAnswer=[${ans}]”
i=0
而read-r行;做
((i++)
声明var$i=“${line}”
完成