Loading ...
Sorry, an error occurred while loading the content.

some help on menus

Expand Messages
  • CSM30005
    Hi, I have been trying to write a menu in with shell scripts and I keep getting an error. Can anyone see where my error is in the following code ? echo Main
    Message 1 of 3 , Nov 30, 1998
    • 0 Attachment
      Hi,
      I have been trying to write a menu in with shell scripts and I keep
      getting an error.

      Can anyone see where my error is in the following code ?

      echo Main Menu
      stop=1
      while test $ stop-eq 0
      do
      cat <<MENUEND
      1 : SHOW DATE
      2 : SHOW CURRENT WORKING DIR
      3 : QUIT
      MENUEND
      echo
      echo -n your choice?
      read answer
      echo
      case $answer in
      "1")
      clear
      date
      ;;
      "2")
      pwd
      ;;
      "3")
      stop=1
      ;;
      *)
      echo Invalid choice
      ;;
      esac
      done


      If anyone could see where the error is, it would help a lot.
      Brian
    • Patrick Davalan
      ... Hmmm , the problem is quite difficult. I think that anybody who wrote the script above is able to find the error quickly , you probably found it before you
      Message 2 of 3 , Nov 30, 1998
      • 0 Attachment
        CSM30005 wrote:
        >
        > From: "CSM30005" <CSM30005@...>
        >
        > Hi,
        > I have been trying to write a menu in with shell scripts and I keep
        > getting an error.
        >
        > Can anyone see where my error is in the following code ?
        >
        > echo Main Menu
        > stop=1
        > while test $ stop-eq 0
        > do
        > cat <<MENUEND
        > 1 : SHOW DATE
        > 2 : SHOW CURRENT WORKING DIR
        > 3 : QUIT
        > MENUEND
        > echo
        > echo -n your choice?
        > read answer
        > echo
        > case $answer in
        > "1")
        > clear
        > date
        > ;;
        > "2")
        > pwd
        > ;;
        > "3")
        > stop=1
        > ;;
        > *)
        > echo Invalid choice
        > ;;
        > esac
        > done
        >
        > If anyone could see where the error is, it would help a lot.
        > Brian
        >
        Hmmm , the problem is quite difficult.
        I think that anybody who wrote the script above is able to find the error
        quickly , you probably found it before you receive the message.
        I just see 2 errors ( but may be i am not a good syntax checker )
        line 3 : syntax error : some space not at a good place.
        > while test $ stop-eq 0
        try : while test $stop -eq 0
        line 2 : logic ( or misunderstanding error )
        you set error to 1 , but the while loop will be entered only when stop is 0 ;
        thus the 2 and 3rd line should be
        stop=0
        while test $stop -eq 0
        i don't see any error below , it should work fine and be a very useful script!
        it happens to everybody to spend time for some stupid errors , but you probably
        don't need help to correct.
      • Leonardo Milano
        Hi Brian, below I show you a tcsh free version of the menu you want. ;-) I hope this helps, Leo PS: you can check csh man page for more ... ##### begin #####
        Message 3 of 3 , Nov 30, 1998
        • 0 Attachment
          Hi Brian,

          below I show you a tcsh "free" version of the menu you want.
          ;-)

          I hope this helps,

          Leo

          PS: you can check csh man page for more ...

          ##### begin #####
          #! /bin/tcsh
          echo Main Menu
          set stop=0

          while ($stop != 1)

          echo 1 : SHOW DATE
          echo 2 : SHOW CURRENT WORKING DIR
          echo 3 : QUIT
          echo " "

          set answer = $<

          switch ($answer)
          case "1":
          date
          echo " "
          breaksw
          case 2:
          pwd
          echo " "
          breaksw
          case 3:
          exit
          breaksw
          endsw
          end
          ##### end #####

          ------------------------------------------------------------------------
          Leonardo J. Milano leo@... Argentina
          http://welcome.to/leo.milano TEL:(54-1)781-6755 ext 117 ICQ:21499474
          ------------------------------------------------------------------------

          > From: "CSM30005" <CSM30005@...>
          >
          > Hi,
          > I have been trying to write a menu in with shell scripts and I keep
          > getting an error.
          >
          > Can anyone see where my error is in the following code ?
          >
          > echo Main Menu
          > stop=1
          > while test $ stop-eq 0
          > do
          > cat <<MENUEND
          > 1 : SHOW DATE
          > 2 : SHOW CURRENT WORKING DIR
          > 3 : QUIT
          > MENUEND
          > echo
          > echo -n your choice?
          > read answer
          > echo
          > case $answer in
          > "1")
          > clear
          > date
          > ;;
          > "2")
          > pwd
          > ;;
          > "3")
          > stop=1
          > ;;
          > *)
          > echo Invalid choice
          > ;;
          > esac
          > done
          >
          >
          > If anyone could see where the error is, it would help a lot.
          > Brian
        Your message has been successfully submitted and would be delivered to recipients shortly.