Results 1 to 8 of 8

Thread: Shell menu: returning to menu if a function fails.

  1. #1
    Join Date
    Mar 2010
    Location
    Ohio
    Beans
    465
    Distro
    Kubuntu

    Shell menu: returning to menu if a function fails.

    I'm building a menu for my frequently accessed CLI commands, and I'm trying to work it out so that if a function fails where there were several in the menu option, it will return to the main menu.

    Where the following script calls exit 1, what would I put to cause it to skip the remaining commands in the sequence without exiting the script?

    Code:
         cd /media/IKUSB || { echo -e " "
         	                  echo -e "\t Failed to change directory";
         	                  echo -e "\t Has the Ironkey been mounted & Unlocked?";
                              echo -e " ";
         	                  echo -e "\t Script will exit upon pressing Enter.";
                              echo -e " ";
                              read enterKey;
                              exit 1; };

  2. #2
    Join Date
    Dec 2010
    Location
    Vaadduva, Shri Langka
    Beans
    113
    Distro
    Kubuntu 10.04 Lucid Lynx

    Re: Shell menu: returning to menu if a function fails.

    I think "break" should do the job
    "කරපු තරමක් කෙරුවෙ උදව්... අහපු තරමක් ඇහුවෙ බෙනුම්..." - If You Expect To Help... Expect Earshot...

  3. #3
    Join Date
    Mar 2010
    Location
    Ohio
    Beans
    465
    Distro
    Kubuntu

    Re: Shell menu: returning to menu if a function fails.

    Quote Originally Posted by ChipOManiac View Post
    I think "break" should do the job
    Unfortunately, that has the effect of exiting the script entirely, the same as exit

  4. #4
    Join Date
    Dec 2010
    Location
    Vaadduva, Shri Langka
    Beans
    113
    Distro
    Kubuntu 10.04 Lucid Lynx

    Smile Re: Shell menu: returning to menu if a function fails.

    Quote Originally Posted by Ranko Kohime View Post
    Unfortunately, that has the effect of exiting the script entirely, the same as exit
    Just put it under a while loop with "true" or something like that so the main part keeps running until the break... the break will then break the while and continue with the script.. (although I really can't tell what your script is attempting to do from the code specified)

    ^^^ IGNORE ^^^
    Last edited by ChipOManiac; March 16th, 2011 at 11:43 AM. Reason: Had A Better Idea
    "කරපු තරමක් කෙරුවෙ උදව්... අහපු තරමක් ඇහුවෙ බෙනුම්..." - If You Expect To Help... Expect Earshot...

  5. #5
    Join Date
    Dec 2010
    Location
    Vaadduva, Shri Langka
    Beans
    113
    Distro
    Kubuntu 10.04 Lucid Lynx

    Re: Shell menu: returning to menu if a function fails.

    Okay... from the code it seems to me that you have tried to access a folder in /media/ which means it has to be a mount thingy...

    I use this script to run my homeworld for linux program

    Code:
      if [ -d /media/HOMEWORLD ]
      then
        echo -e "   ISO Mounted\n   Executing HomeWorld 1 SDL\n   "
        sudo ./homeworld0.3 /window /pilotView /device fx /CDpath "/media/HOMEWORLD"
      else
    #    echo -n "   CD Not In Drive, Try Again? Y/N?     "
    #    read -e ICDReTry
        echo -e "   ISO Not Mounted\n   Mounting Homeworld 1 ISO\n   "
        sudo mkdir /media/HOMEWORLD
        sudo mount -t iso9660 -o loop /psw/homeworld1/homeworld.iso /media/HOMEWORLD
        echo -e "   ISO Mounted\n   Executing HomeWorld 1 SDL\n   "
        sudo ./homeworld0.3 /window /pilotView /device fx /CDpath "/media/HOMEWORLD"
        sudo umount /media/HOMEWORLD
        sudo rmdir /media/HOMEWORLD
      fi
    that "[ -d /media/HOMEWORLD ]" checks to see if that directory exists...

    Have I understood correctly?
    "කරපු තරමක් කෙරුවෙ උදව්... අහපු තරමක් ඇහුවෙ බෙනුම්..." - If You Expect To Help... Expect Earshot...

  6. #6
    Join Date
    Mar 2010
    Location
    Ohio
    Beans
    465
    Distro
    Kubuntu

    Re: Shell menu: returning to menu if a function fails.

    Quote Originally Posted by ChipOManiac View Post
    Just put it under a while loop with "true" or something like that so the main part keeps running until the break... the break will then break the while and continue with the script.. (although I really can't tell what your script is attempting to do from the code specified)

    ^^^ IGNORE ^^^
    That just might do the trick. I'll try it out and see how it works.

  7. #7
    Join Date
    Mar 2010
    Location
    Ohio
    Beans
    465
    Distro
    Kubuntu

    Re: Shell menu: returning to menu if a function fails.

    Quote Originally Posted by ChipOManiac View Post
    that "[ -d /media/HOMEWORLD ]" checks to see if that directory exists...
    That -d command looks handy, I think I'll use it in my script.

    *Ranko Kohime is relatively new to shell-scripting

  8. #8
    Join Date
    Mar 2010
    Location
    Ohio
    Beans
    465
    Distro
    Kubuntu

    Re: Shell menu: returning to menu if a function fails.

    Ok, here's another question: How does one do a "while" loop based upon the exit code of a command?

    Is it
    Code:
    while : 0
    or something else?

    Edit: I should probably mention, this is inside of a menu script, so there's a "while" loop controlling the menu. Would having a "while" loop inside the menu break correctly? (i.e., break the menu option and return to the main menu?)

    Edit 2: Well, I guess the topic implied that already... Shows how much I'm paying attention.
    Last edited by Ranko Kohime; March 19th, 2011 at 10:39 PM.

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
  •