ダイアログボックスでいくつかの必須フィールドを設定します。

ダイアログボックスでいくつかの必須フィールドを設定します。

次のスクリプトはダイアログを作成します。ユーザーはEnterいつでもキーを押すことができ、スクリプトは続行されます。Enterユーザーがすべてのフィールドを入力できるように、このキーをブロックする必要があります。どうすればいいですか?

#!/bin/bash
shell=""
groups=""
user=""
home=""
exec 3>&1
dialog --separate-widget $'\n' --ok-label "Ok" \
          --backtitle "Linux User Managment" \
          --title "new" \
          --form "creating new " \
15 80 0 \
        "field1: "              1 1 "$user"             1 25 40 0 \
        "field2:"               2 1 "$shell"            2 25 40 0 \
        "field3:"               3 1 "$groups"           3 25 40 0 \
        "field4:"               4 1 "$home"             4 25 40 0 \

# aggiungi dimensione quota

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

ここに画像の説明を入力してください。

ベストアンサー1

ダイアログ プログラムにフィールドの内容を検証するオプションがないと思います。プログラムがdialogループ内で実行されるようにし、ユーザーが無効な値(空のフィールドなど)を入力すると、ダイアログボックスに戻ります。

#!/bin/bash
shell=
groups=
user=
home=
error_message=
IFS=$'\n'; set -f
while [[ -z $shell || -z $groups || -z $user || -z $home ]]; do
  set $(dialog … --form="creating new $error_message" … --output-fd=3 3>&1 >/dev/tty)
  shell=$1 groups=$1 user=$1 home=$1
  error_message="(fields must not be empty)"
done
unset IFS; set +f

おすすめ記事