2

I would like to use whiptail to create a toolbox which runs external scripts when a menu item is chosen.

I have the following code

#!/bin/bash

OPTION=$(whiptail --title "IT ToolBox v0.1" --menu "Choose your option" 15 60 4 \
"1" "Get users dropped from Active Directory" \
"2" "Work in progress" \
"3" "Work in progress" \
"4" "Work in progress"  3>&1 1>&2 2>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "Your chosen option:" $OPTION
else
    echo "You chose Cancel."
fi

case $RETVAL in
    1) echo "Get users dropped from Active Directory"
    2) echo "Invalid option. Quitting";;
    3) echo "Invalid option. Quitting";;
    4) echo "Invalid option. Quitting";;
    *) echo "Invalid option. Quitting";;
esac

How do I tell the script to execute the file gudfad.sh when chosen? My understanding is that the command is to be added in the case area -- for example:

case $RETVAL in
    1) echo "Get users dropped from Active Directory"
       gudfad.sh;;
    2) echo "Invalid option. Quitting";;
    3) echo "Invalid option. Quitting";;
    4) echo "Invalid option. Quitting";;
    *) echo "Invalid option. Quitting";;
esac

However, when I run this and choose option 1, I get the message:

Your chosen option: 1
Invalid option. Quitting
2
  • 1
    $RETVAL is an empty string. Commented Jan 16, 2017 at 11:58
  • Don't forget to click the checkmark to accept an answer that solves your problem! Commented Jan 16, 2017 at 19:25

1 Answer 1

4

User choice is in OPTION, not RETVAL.

Change:

case $RETVAL in

To:

case "$OPTION" in

It's good to add set -u at the top of your bash scripts so that you are warned when you use undefined variables.

It's also good to always quote your variables: "$var", not $var. There are exceptions but they are rare.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.