Find the answer to your Linux question:
Results 1 to 7 of 7
Well, this is my first post, so "Hello there!" I'm learnig to use shell script at the moment and I bumped into a problem... When I run the below menu ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2011
    Location
    Belgium
    Posts
    6

    Scripting problem


    Well, this is my first post, so "Hello there!"
    I'm learnig to use shell script at the moment and I bumped into a problem... When I run the below menu script(with dialog), my screen clears and I only get my prompt again. No error, nothing. Just my prompt, way down below.

    Can someone tell me where the problem might be?

    Code:
    #!/bin/bash
    #
    #Menu created with dialog
    
    dialog --backtitle "Mediaserver Vanoppen-Verhasselt Main Menu" --title "Mediaserver menu" --menu "Move using [UP] [DOWN], [Enter] to select" 15 50 3 \
    Date/Time "shows Date and Time"\
    Calendar "To see the calendar of this month"\
    Editor "Start with some scripting"\
    Movies "Show Movies list" 2>/tmp/menuitem.$$
    
    menuitem=`cat /tmp/menuitem.$$`
    
    opt=$?
    
    case $menuitem in
    Date/Time) date;;
    Calendar) cal;;
    Editor) nano;;
    Movies) `ls /media/EXHD/Movies` ;;
    esac

  2. #2
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    626
    I've done a couple of menu-driven scripts. they look kind of like this:
    Code:
    while :
    do
    clear
    echo -e "****** Main - Menu ******"
    echo "What would you like to do?..."
    echo ""
    echo "1. blah"
    echo "2. blah blah"
    echo "3. blah blah blah"
    echo "4. blah blah blah blah"
    echo "5. quit"
    echo ""
    echo -n "Please enter your choice (1 - 5):";
    
    read opt
    case $opt in
    
    1)  echo "blah";
    echo "Press enter to return";
    read enterkey;;
    
    2) echo "blah blah";
    echo "Press enter to return";
    read enterkey;;
    
    3) echo "blah blah blah";
    echo "Press enter to return";
    read enterkey;;
    
    4) echo "blah blah blah blah";
    echo "Press enter to return";
    read enterkey;;
    
    5) echo "goodbye";
    exit 0;
    
    *) echo "doh!  not a valid key";
    echo "Press enter to return";
    read enterkey;;
    
    esac
    done
    so perhaps you need a while loop
    linux user # 503963

  3. #3
    Just Joined!
    Join Date
    Oct 2011
    Posts
    1
    Hi,

    I'm learning too, but having the same problems.

    Best regard

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Dec 2011
    Location
    Belgium
    Posts
    6
    Thanks for your reply, but without the dialog utility, it works perfect just as your example. But when I'm using this dialog utility... I'm just getting a black screen and on the bottom there is my prompt again, as if the whole menu is there but I can't see it or it booted but closed immediately.

  6. #5
    Just Joined!
    Join Date
    Dec 2011
    Location
    Belgium
    Posts
    6
    Anybody?

  7. #6
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    626
    I never could get your script to run, so I wrote it from scratch. Let me give you some pointers though:

    1) Your case statements are all wrong. Its expecting a '0' or a '1' or '255' (escape key) as input. Other inputs can be added as well, but its not looking for names. So, you need use if statements to determine what the actual input was.

    2) I also added a trap statement to clean up the tempfile.
    Code:
    #!/bin/bash
    DIALOG=${DIALOG=dialog}
    tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$
    trap "rm -f $tempfile" 0 1 2 5 15
    
    $DIALOG --clear --backtitle "Mediaserver Vanoppen-Verhasselt Main Menu" --title "Mediaserver Menu" \
            --menu "Move using [UP] [DOWN], [Enter] to select:" 20 51 4 \
            "Date/Time" "shows Date and Time"\
            "Calendar" "To see the calendar of this month"\
            "Editor" "Start with some scripting"\
            "Movies" "Show Movies list" 2> $tempfile
    
    retval=$?
    
    choice=`cat $tempfile`
    
    case $retval in
      0)
        if [ $choice == "Date/Time" ];then
            echo `date`
        elif [ $choice == "Calendar" ];then
            echo `cal`
        elif [ $choice == "Editor" ]; then
            echo `nano`
        elif [ $choice == "Movies" ]; then
            echo `ls /media/EXHD/Movies`
            fi;;
      1)
        echo "Cancelled.";;
      255)
        echo "ESC pressed.";;
    esac
    linux user # 503963

  8. #7
    Just Joined!
    Join Date
    Dec 2011
    Location
    Belgium
    Posts
    6
    THANK YOU VERY MUCH!!! And thanks for the effort of re-writing the script!!! I'll keep in mind the advice you gave me. Again, thank you very much!

Posting Permissions

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