menu option 'Y' or 'y'

menu option 'Y' or 'y'

Post by Yolanda Villanov » Thu, 12 Jul 2001 20:53:44



I am writing a menu script and I need to allow the user to enter eiter
upper case 'Y' or 'y'.
I tried using this

echo "          Are you sure you want to exit?"
read exitreply
tr "$exitreply" upper
if test "$exitreply" = "Y"
then
logout
else
"$exitreply" = "N"
fi

It seems to work, but I have to press ctrl D to exit the script

Thanks

 
 
 

menu option 'Y' or 'y'

Post by Sean O'Donnel » Fri, 13 Jul 2001 03:05:48


you are using the tr command incorrectly.   It is waiting for input, which
is why you are having to hit cntl D to break out.  What you probably want to
do is:

...
exitreply=$(echo "$exitreply" | tr "[a-z]" "[A-Z]")
if [ "$exitreply" = "Y" ]
then
logout
else
exitreply="N"
fi
...

Even better, eliminate the uppercase conversion altogether:

if [ "$exitreply" = "Y" -o "$exitreply" = "y" ]
then
...

Also, you may want to use exit(1) instead of logout(1).

Finally, check your syntax:
"$exitreply"="N"
is incorrect.  It should be
exitreply="N"

On some systems (e.g. Solaris), there is a ckyorn(1) command as well.

Sean O'Donnell
Lucent Technologies


>I am writing a menu script and I need to allow the user to enter eiter
>upper case 'Y' or 'y'.
>I tried using this

>echo "          Are you sure you want to exit?"
>read exitreply
>tr "$exitreply" upper
>if test "$exitreply" = "Y"
>then
>logout
>else
>"$exitreply" = "N"
>fi

>It seems to work, but I have to press ctrl D to exit the script

>Thanks


 
 
 

1. '-i' option for 'cp' and 'mv'

I am using a system running System V on a 386 machine.  In 4.3 bsd, 'cp'
and 'mv' have the option '-i' which will warn me if the file exists.
In the system I am using, only 'rm' has such an option.   I would like to change
it so that '-i' will work for 'cp' and 'mv' as well.  Can someone tell me how to
do it?

Many thanks

philip

2. RH7 and VMWare Express

3. 'diff' option like 'grep -q'?

4. PPP Linux vs W95/98

5. in 'getopt()', how to handle multiple options in the 'optarg' string?

6. library problem!

7. XF86Config: 'EarlySC','BlankDelay' options gone?

8. Q: Does anybody make an SBUS FC-AL adapter that works with 3rd-party FC-AL disks?

9. 'netstat' and '-f inet' option

10. Need help for 'ipfw' with 'fwd' option

11. How to disable 'Toggle Menu Bar' option with dtterm

12. 'setup' script doesn't display menu

13. Can we remove 'Toggle Menu Bar' menu item which comes with dtterm ?