/contrib/dialog/samples/inputmenu4

https://bitbucket.org/freebsd/freebsd-head/ · Shell · 86 lines · 73 code · 9 blank · 4 comment · 6 complexity · a390cd0721a057a3bc3580d6a9f848f9 MD5 · raw file

  1. #! /bin/sh
  2. # $Id: inputmenu4,v 1.8 2010/01/13 10:33:35 tom Exp $
  3. #
  4. # "inputmenu1" with a different label for the extra-button
  5. . ./setup-vars
  6. backtitle="An Example for the use of --inputmenu:"
  7. ids=`id|sed -e 's/([^)]*)//g'`
  8. uid=`echo "$ids" | sed -e 's/^uid=//' -e 's/ .*//'`
  9. gid=`echo "$ids" | sed -e 's/^.* gid=//' -e 's/ .*//'`
  10. user="$USER"
  11. home="$HOME"
  12. returncode=0
  13. while test $returncode != 1 && test $returncode != 250
  14. do
  15. exec 3>&1
  16. value=`$DIALOG --clear --ok-label "Create" \
  17. --extra-label "Edit" \
  18. --backtitle "$backtitle" "$@" \
  19. --inputmenu "Originally I designed --inputmenu for a \
  20. configuration purpose. Here is a possible piece of a configuration program." \
  21. 20 50 10 \
  22. "Username:" "$user" \
  23. "UID:" "$uid" \
  24. "GID:" "$gid" \
  25. "HOME:" "$home" \
  26. 2>&1 1>&3`
  27. returncode=$?
  28. exec 3>&-
  29. case $returncode in
  30. $DIALOG_CANCEL)
  31. "$DIALOG" \
  32. --clear \
  33. --backtitle "$backtitle" \
  34. --yesno "Really quit?" 10 30
  35. case $? in
  36. $DIALOG_OK)
  37. break
  38. ;;
  39. $DIALOG_CANCEL)
  40. returncode=99
  41. ;;
  42. esac
  43. ;;
  44. $DIALOG_OK)
  45. "$DIALOG" \
  46. --clear \
  47. --backtitle "$backtitle" \
  48. --msgbox "useradd \n\
  49. -d $home \n\
  50. -u $uid \n\
  51. -g $gid \n\
  52. $user" 10 40
  53. ;;
  54. $DIALOG_EXTRA)
  55. tag=`echo "$value" |sed -e 's/^RENAMED //' -e 's/:.*//'`
  56. item=`echo "$value" |sed -e 's/^.*:[ ]*//' -e 's/[ ]*$//'`
  57. case "$tag" in
  58. Username)
  59. user="$item"
  60. ;;
  61. UID)
  62. uid="$item"
  63. ;;
  64. GID)
  65. gid="$item"
  66. ;;
  67. HOME)
  68. home="$item"
  69. ;;
  70. esac
  71. ;;
  72. $DIALOG_ESC)
  73. echo "ESC pressed."
  74. break
  75. ;;
  76. esac
  77. done