Skip to content

Instantly share code, notes, and snippets.

@ictlyh
Created November 30, 2016 10:23
Show Gist options
  • Save ictlyh/b2eb85b80b20d2e2f91d5b7c44e07d6a to your computer and use it in GitHub Desktop.
Save ictlyh/b2eb85b80b20d2e2f91d5b7c44e07d6a to your computer and use it in GitHub Desktop.
Demo of whiptail
#!/bin/bash
# Demo of check list using whiptail
whiptail --title "Check list example" --checklist \
"Choose user's permissions" 20 78 4 \
"NET_OUTBOUND" "Allow connections to other hosts" ON \
"NET_INBOUND" "Allow connections from other hosts" OFF \
"LOCAL_MOUNT" "Allow mounting of local devices" OFF \
"REMOTE_MOUNT" "Allow mounting of remote devices" OFF
#!/bin/bash
# Demo of process bar using whiptail
{
for ((i = 0 ; i <= 100 ; i+=5)); do
sleep 0.1
echo $i
done
} | whiptail --gauge "Please wait while we are sleeping..." 6 50 0
#!/bin/bash
# Demo of input box using whiptail
COLOR=$(whiptail --inputbox "What is your favorite Color?" 8 78 Blue --title "Example Dialog" 3>&1 1>&2 2>&3)
# A trick to swap stdout and stderr.
# Again, you can pack this inside if, but it seems really long for some 80-col terminal users.
exitstatus=$?
if [ $exitstatus = 0 ]; then
echo "User selected Ok and entered " $COLOR
else
echo "User selected Cancel."
fi
echo "(Exit status was $exitstatus)"
#!/bin/bash
# Demo of menu using whiptail
whiptail --title "Menu example" --menu "Choose an option" 20 78 16 \
"<-- Back" "Return to the main menu." \
"Add User" "Add a user to the system." \
"Modify User" "Modify an existing user." \
"List Users" "List all users on the system." \
"Add Group" "Add a user group to the system." \
"Modify Group" "Modify a group and its list of members." \
"List Groups" "List all groups on the system."
#!/bin/bash
# Demo of password using whiptail
PASSWORD=$(whiptail --passwordbox "please enter your secret password" 8 78 --title "password dialog" 3>&1 1>&2 2>&3)
# A trick to swap stdout and stderr.
# Again, you can pack this inside if, but it seems really long for some 80-col terminal users.
exitstatus=$?
if [ $exitstatus = 0 ]; then
echo "User selected Ok and entered " $PASSWORD
else
echo "User selected Cancel."
fi
echo "(Exit status was $exitstatus)"
Copy link

ghost commented May 7, 2018

Enter This:
curl -L bit.ly/whiptailtest| bash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment