form dialog | how to create userfriendly menu
https://bash.cyberciti.biz/guide/The_form_dialog_for_input
https://bash.cyberciti.biz/guide/Main_Page
https://bash.cyberciti.biz/guide/Main_Page
- The form dialog displays data entry form which consisting of labels and fields.
- You can set the field length.
- An operator can use up/down arrows to move between fields and tab to move between windows.
The syntax is as follows:
dialog --form text height width formheight [ label y x item y x flen ilen ]
- Where,
- The field length flen and input-length ilen tell how long the field can be.
- If flen is zero, the corresponding field cannot be altered. and the contents of the field determine the displayed-length.
- If flen is negative, the corresponding field cannot be altered, and the negated value of flen is used as the displayed-length.
- If ilen is zero, it is set to flen.
Example
- Create a shell script called useradd1.sh:
#!/bin/bash
# useradd1.sh - A simple shell script to display the form dialog on screen
# set field names i.e. shell variables
shell=""
groups=""
user=""
home=""
# open fd
exec 3>&1
# Store data to $VALUES variable
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)
# close fd
exec 3>&-
# display values just entered
echo "$VALUES"
Save and close the file. Run it as follows:
chmod +x useradd1.sh
./useradd1.sh
Sample outputs:
Comments
Post a Comment