Unix Shell - How to create interactive menus under Unix

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > December 2006 > How to create interactive menus under Unix





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author How to create interactive menus under Unix
Guytou

2006-12-14, 7:29 pm

Hi



I learn how to write SHELL scripts (sh) or (ksh).

I will like to learn how to write interactive scripts who generate menus.

Here the script which I found on the WEB but which does not go. I do not
know why.

Thanks for helping me to make it turn or propose another script or another
easier model to me.

Thank you also to advise me tutoriels or Web sites which will help me with
better learning how to write interactive menus under UNIX.

This script does not function. Thank you to correct it to me.



#! /bin/sh
opt1="Enter the name of the repertory."
opt2="Enter the name of the file to find."
opt3="Enter the current date."
opt4="Exit."
echo -e "\nMENU RECHERCHE FICHIER\n"

echo -e " Option Description\n"

PS3="
Enter your choice: "

select option in "$opt1" "$opt2" "$opt3" "$opt4"

do
case $option in
$opt1) echo " : $opt1"
continuous ;;
$opt2) echo "You chose the option : $opt2"
continuous ;;
$opt3) echo "You chose the option : $opt3"
continuous ;;
$opt4) echo "You chose the option : $opt4"
continuous ;;
*) echo "This option does not exist";
break ;;
esac
done



This script does not function. Thank you to correct it to me.


Janis Papanagnou

2006-12-14, 7:29 pm

Guytou wrote:
> Hi
>
>
>
> I learn how to write SHELL scripts (sh) or (ksh).
>
> I will like to learn how to write interactive scripts who generate menus.
>
> Here the script which I found on the WEB but which does not go. I do not
> know why.
>
> Thanks for helping me to make it turn or propose another script or another
> easier model to me.
>
> Thank you also to advise me tutoriels or Web sites which will help me with
> better learning how to write interactive menus under UNIX.
>
> This script does not function. Thank you to correct it to me.
>
>
>
> #! /bin/sh
> opt1="Enter the name of the repertory."
> opt2="Enter the name of the file to find."
> opt3="Enter the current date."
> opt4="Exit."
> echo -e "\nMENU RECHERCHE FICHIER\n"
>
> echo -e " Option Description\n"
>
> PS3="
> Enter your choice: "
>
> select option in "$opt1" "$opt2" "$opt3" "$opt4"
>
> do
> case $option in
> $opt1) echo " : $opt1"
> continuous ;;
> $opt2) echo "You chose the option : $opt2"
> continuous ;;
> $opt3) echo "You chose the option : $opt3"
> continuous ;;
> $opt4) echo "You chose the option : $opt4"
> continuous ;;
> *) echo "This option does not exist";
> break ;;
> esac
> done
>
>
>
> This script does not function. Thank you to correct it to me.


What does not function? What input provides what output or error?

Did you, maybe, get an error message that a program "continuous" could
not be found? But that would not be a problem of the ksh 'select' menu;
the select statement is okay in principle.

/bin/sh may not be a Kornshell, so change the first line to #!/bin/ksh

On what system are you working?

Janis
Bill Marcum

2006-12-14, 7:29 pm

Xref: number1.nntp.dca.giganews.com comp.unix.shell:192260

On Thu, 14 Dec 2006 20:32:55 +0100, Guytou
<mapasa@free.fr> wrote:
> Hi
>
>
>
> I learn how to write SHELL scripts (sh) or (ksh).
>
> I will like to learn how to write interactive scripts who generate menus.
>
> Here the script which I found on the WEB but which does not go. I do not
> know why.
>
> Thanks for helping me to make it turn or propose another script or another
> easier model to me.
>
> Thank you also to advise me tutoriels or Web sites which will help me with
> better learning how to write interactive menus under UNIX.
>
> This script does not function. Thank you to correct it to me.
>

What errors do you get? "continuous" is not a command, perhaps it should
be "continue", and it looks like there is a "while" missing before "do".


>
>
> #! /bin/sh
> opt1="Enter the name of the repertory."
> opt2="Enter the name of the file to find."
> opt3="Enter the current date."
> opt4="Exit."
> echo -e "\nMENU RECHERCHE FICHIER\n"
>
> echo -e " Option Description\n"
>
> PS3="
> Enter your choice: "
>
> select option in "$opt1" "$opt2" "$opt3" "$opt4"
>
> do
> case $option in
> $opt1) echo " : $opt1"
> continuous ;;
> $opt2) echo "You chose the option : $opt2"
> continuous ;;
> $opt3) echo "You chose the option : $opt3"
> continuous ;;
> $opt4) echo "You chose the option : $opt4"
> continuous ;;
> *) echo "This option does not exist";
> break ;;
> esac
> done
>
>
>
> This script does not function. Thank you to correct it to me.
>
>



--
Satellite Safety Tip #14:
If you see a bright streak in the sky coming at you, duck.
Chris F.A. Johnson

2006-12-14, 7:29 pm

On 2006-12-14, Guytou wrote:
>
> I learn how to write SHELL scripts (sh) or (ksh).
>
> I will like to learn how to write interactive scripts who generate menus.
>
> Here the script which I found on the WEB but which does not go. I do not
> know why.
>
> Thanks for helping me to make it turn or propose another script or another
> easier model to me.
>
> Thank you also to advise me tutoriels or Web sites which will help me with
> better learning how to write interactive menus under UNIX.


You can find links to various tutorials and other resources at
<http://cfaj.freeshell.org/shell>.

> This script does not function. Thank you to correct it to me.
>
>
> #! /bin/sh
> opt1="Enter the name of the repertory."
> opt2="Enter the name of the file to find."
> opt3="Enter the current date."
> opt4="Exit."
> echo -e "\nMENU RECHERCHE FICHIER\n"
>
> echo -e " Option Description\n"
>
> PS3="
> Enter your choice: "
>
> select option in "$opt1" "$opt2" "$opt3" "$opt4"
>
> do
> case $option in
> $opt1) echo " : $opt1"
> continuous ;;
> $opt2) echo "You chose the option : $opt2"
> continuous ;;
> $opt3) echo "You chose the option : $opt3"
> continuous ;;
> $opt4) echo "You chose the option : $opt4"
> continuous ;;
> *) echo "This option does not exist";
> break ;;
> esac
> done
>
>
> This script does not function. Thank you to correct it to me.


Change "continuous" to "continue".

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Janis Papanagnou

2006-12-14, 7:29 pm

Bill Marcum wrote:
> On Thu, 14 Dec 2006 20:32:55 +0100, Guytou
> <mapasa@free.fr> wrote:
>
>
> What errors do you get? "continuous" is not a command, perhaps it should
> be "continue", and it looks like there is a "while" missing before "do".


No, that 'do' as part of the 'select' statement is correct.

Janis
[vbcol=seagreen]
>
[snip][vbcol=seagreen]
Brian Mac

2006-12-15, 1:20 pm

Hi Guytou,

You will have to use the Korn shell to use a select statement. The
first line of the script should be changed to:

#!/bin/ksh

Also, when writing shell scripts, there should not be any spaces on the
first line and the #! need to be the first characters on the line.

The script looks pretty good but for a few points:

1. Continuous is not a valid Korn shell command. Generally speaking,
you'll want to use continue to jump to the next item in a loop.
However, with a select loop you will want to break out (assuming a
valid menu selection is chosen) by using the break statement (dropping
you outside of the select statement but not the entire script).
Otherwise you'll be prompted forever.

2. I would not put a break statement in your catch-all pattern of *.
A select statement will only accept one of the valid values and loop if
a valid entry is not selected. For your catch-all I would recommend
printing a usage message - maybe something like:

echo "Please select a valid entry (Press Enter to redraw menu)"

No need to write continue or anything else. Pressing enter will redraw
the menu.

Hope this helps,
Brian

Guytou wrote:
> Hi
>
>
>
> I learn how to write SHELL scripts (sh) or (ksh).
>
> I will like to learn how to write interactive scripts who generate menus.
>
> Here the script which I found on the WEB but which does not go. I do not
> know why.
>
> Thanks for helping me to make it turn or propose another script or another
> easier model to me.
>
> Thank you also to advise me tutoriels or Web sites which will help me with
> better learning how to write interactive menus under UNIX.
>
> This script does not function. Thank you to correct it to me.
>
>
>
> #! /bin/sh
> opt1="Enter the name of the repertory."
> opt2="Enter the name of the file to find."
> opt3="Enter the current date."
> opt4="Exit."
> echo -e "\nMENU RECHERCHE FICHIER\n"
>
> echo -e " Option Description\n"
>
> PS3="
> Enter your choice: "
>
> select option in "$opt1" "$opt2" "$opt3" "$opt4"
>
> do
> case $option in
> $opt1) echo " : $opt1"
> continuous ;;
> $opt2) echo "You chose the option : $opt2"
> continuous ;;
> $opt3) echo "You chose the option : $opt3"
> continuous ;;
> $opt4) echo "You chose the option : $opt4"
> continuous ;;
> *) echo "This option does not exist";
> break ;;
> esac
> done
>
>
>
> This script does not function. Thank you to correct it to me.


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com