对话框--输入框

对话框--输入框

按照下面的脚本,我有一个保留所有变量的唯一变量,我需要将每个变量与以下内容分开$VALUES

#!/bin/bash
shell=""
groups=""
user=""
home=""
exec 3>&1
VALUES=$(dialog --ok-label "Submit" \
          --backtitle "Linux User Managment" \
          --title "Useradd" \
          --form "Create a new user" \
15 50 0 \
        "Username:" 1 1 "$user"         1 10 10 0 \
        "Shell:"    2 1 "$shell"        2 10 15 0 \
        "Group:"    3 1 "$groups"       3 10 8 0 \
        "HOME:"     4 1 "$home"         4 10 40 0 \
2>&1 1>&3)
exec 3>&-

echo "$VALUES"

答案1

这对我有用:

#!/bin/bash
shell=""
groups=""
user=""
home=""
exec 3>&1
dialog --separate-widget $'\n' --ok-label "Submit" \
          --backtitle "Linux User Managment" \
          --title "Useradd" \
          --form "Create a new user" \
15 50 0 \
        "Username:" 1 1 "$user"         1 10 10 0 \
        "Shell:"    2 1 "$shell"        2 10 15 0 \
        "Group:"    3 1 "$groups"       3 10 8 0 \
        "HOME:"     4 1 "$home"         4 10 40 0 \
2>&1 1>&3 | {
  read -r user
  read -r shell
  read -r groups
  read -r home

  echo $user
  echo $shell
  echo $groups
  echo $home

  #continue script here
}
exec 3>&-

相关内容