Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Catching whiptail checklist results in bash script

  1. #1
    Join Date
    Dec 2012
    Beans
    7

    Catching whiptail checklist results in bash script

    I have googled the heck out of this, and read dozens of examples, but cant quite figure it out...

    I understand how the yes/no buttons work, and can catch those no problem, but I want to give several options to the user, and catch the output in my script, and do something with it.

    Code:
    #! /bin/bash
    
    whiptail --title "Test" --checklist "Choose:" 20 78 15 \
    "John" "" on \
    "Glen" "" off \
    "Adam" "" off \
    
    
    # If "John" is selected, run this function:
    function john {
    echo "You chose John"
    }
    
    # If "Glen" is selected, run this function:
    function glen {
    echo "You chose Glen"
    }
    
    # If "Adam" is selected, run this function:
    function adam {
    echo "You chose Glen"
    }
    
    exit
    I can see the output at the command line when the above script ends, but how can I use it inside the script?

    Also, using the option "--seperate-output" seems to totally suppress the output, rather than seperate it on different lines like it is meant to.

    I would appreciate any help

  2. #2
    Join Date
    Jun 2005
    Location
    Toronto, Canada
    Beans
    Hidden!
    Distro
    Xubuntu 16.04 Xenial Xerus

    Re: Catching whiptail checklist results in bash script

    Checklist sends its output to stderr, so you need to catch it somehow. Not sure if this is the best way, but here is one method:
    Code:
    #!/bin/bash
    
    whiptail --title "Test" --checklist --separate-output "Choose:" 20 78 15 \
    "John" "" on \
    "Glen" "" off \
    "Adam" "" off 2>results
    
    while read choice
    do
    	case $choice in
    		John) echo "You chose John"
    		;;
    		Glen) echo "You chose Glen"
    		;;
    		Adam) echo "You chose Adam"
    		;;
    		*)
    		;;
    	esac
    done < results

  3. #3
    Join Date
    Dec 2012
    Beans
    7

    Re: Catching whiptail checklist results in bash script

    Thanks so much for your help. When I get a chance to test I'll come back and mark as solved.

    Cheers.

  4. #4
    Join Date
    Dec 2012
    Beans
    7

    Re: Catching whiptail checklist results in bash script

    Thanks.

    Your code worked great, and I really appreciate your help.

    Whiptail menus are the final touch on a multiinstaller program similar to Tasksel, but greatly expanded, that I am writing primarily for Raspbian, but will work on any Debian based system, so will test it on Ubuntu too, and make it available.

    I tweaked a little to suit my needs, and heres the working sample code:

    Code:
    #!/bin/bash
    
    function firstroutine {
     echo "running johns function"
    }
    
    function secondroutine {
     echo "running glens function"
    }
    
    
    function thirdroutine {
     echo "running adams function"
    }
    
    whiptail --title "Test" --checklist --separate-output "Choose:" 20 78 15 \
    "John" "" on \
    "Glen" "" off \
    "Adam" "" off 2>results
    
    while read choice
    do
            case $choice in
                    John) firstroutine
                    ;;
                    Glen) secondroutine
                    ;;
                    Adam) thirdroutine
                    ;;
                    *)
                    ;;
            esac
    done < results

  5. #5
    Join Date
    Dec 2012
    Beans
    7

    Re: Catching whiptail checklist results in bash script

    The Thread Tools menu does not contain a 'Solved' function for me to set.

    Can someone educate me, or if I simply don't have access because I'm a n00bie, can someone please set as solved.

    Thanks for all the fish.

  6. #6
    Join Date
    Aug 2011
    Location
    Melbourne, Australia.
    Beans
    Hidden!
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Catching whiptail checklist results in bash script

    Quote Originally Posted by sixfootseven View Post
    The Thread Tools menu does not contain a 'Solved' function for me to set.

    Can someone educate me, or if I simply don't have access because I'm a n00bie, can someone please set as solved.

    Thanks for all the fish.
    Hi,

    You as the OP have the ability of marking as solved.
    Simply use the Thread Tools Menu at top of page and select "Mark as Solved"

    Cheers -
    PopularPages: A very handy Documentation Search Tool used by many.
    PopularPages Wiki Thread
    My New Blog

  7. #7
    Join Date
    Dec 2012
    Beans
    7

    Re: Catching whiptail checklist results in bash script

    Quote Originally Posted by BlinkinCat View Post
    Hi,

    You as the OP have the ability of marking as solved.
    Simply use the Thread Tools Menu at top of page and select "Mark as Solved"

    Cheers -
    No I don't.

    In Thread Tools, I have two options:

    1. Show printable options.
    2. Subscribe to this thread.


    And nothing referring to marking a thread as solved.

    Cheers.


  8. #8
    Join Date
    Aug 2011
    Location
    Melbourne, Australia.
    Beans
    Hidden!
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Catching whiptail checklist results in bash script

    Quote Originally Posted by sixfootseven View Post
    No I don't.

    In Thread Tools, I have two options:

    1. Show printable options.
    2. Subscribe to this thread.


    And nothing referring to marking a thread as solved.

    Cheers.

    Hi,

    They are more like the options when you are not logged on. Are you sure you are logged on when you are viewing the post ? - other than that I have no explanation.

    Cheers -
    PopularPages: A very handy Documentation Search Tool used by many.
    PopularPages Wiki Thread
    My New Blog

  9. #9
    Join Date
    Aug 2011
    Location
    Melbourne, Australia.
    Beans
    Hidden!
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Catching whiptail checklist results in bash script

    Hi again,

    It may be that this is a specialized forum. I have had a quick look at previous threads and none appear to marked as solved. Marking as solved may be for all of the rest of forums other than a few specialized ones.

    If you really wanted to, you could ask a question in the forum help section but actually it may not be worth worrying about.

    All the best -

    Edit : you could also read the Sticky at top of page.
    Last edited by BlinkinCat; December 30th, 2012 at 09:25 AM.
    PopularPages: A very handy Documentation Search Tool used by many.
    PopularPages Wiki Thread
    My New Blog

  10. #10
    Join Date
    May 2007
    Location
    The New Forest
    Beans
    Hidden!
    Distro
    Xubuntu

    Re: Catching whiptail checklist results in bash script

    Thanks for bringing this to our attention - something is afoot, I can't mark this solved either.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •