LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-09-2004, 12:48 PM   #1
Squeak2704
LQ Newbie
 
Registered: Apr 2004
Posts: 3

Rep: Reputation: 0
Shell scripting yes/no case?


Ok, so I am shell scripting retarded and I'm sure then is an easy question to answer.
I have to write a shell script that you must enter two command line arguments. If you enter in two arguments, then it asks if you have a typo, answering Yy or Nn. If no, it goes on to ask if it is a directory etc.

Do I use the case argument for the Yy or Nn? How do I get the shell to continue with the next test if I do use case?
Here is my shell script so far....

if test $# -ne 2
then
echo You must enter exactly 2 command line arguments, please try again.
exit 1
fi


if test $# -eq 2
then echo The command line arguments that you entered are $1 and $2. Did you
make a typo when entering the commands? Y or N.
read choice
case "$choice" in
Y|y) echo Program exiting because you said you had a typo. Please try again.;;
N|n)

if test ! -f $1 && $2
then echo Both files not located, please try again.
etc etc

is this correct or do I use another test like test "$choice" = Y|y??
I'm confused.. my linux prof doesn't like to explain anything..
 
Old 04-09-2004, 02:05 PM   #2
nhs
Member
 
Registered: Aug 2003
Location: Edinburgh, Scotland
Distribution: Gentoo
Posts: 246

Rep: Reputation: 30
I would use

read choice
case "$choice" in
Y|y) echo Program exiting because you said you had a typo. Please try again.
exit 1
;;
N|n)
;;
*) echo You must enter Y or N
;;
esac
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 03:32 PM
Case Statement With Aix Ksh Scripting ']['HeBroken AIX 2 02-09-2005 12:44 PM
KSH Scripting case statement..... ']['HeBroken Programming 1 12-10-2004 10:38 AM
I need a scripting lanuage with case and shell commands rob.rice Programming 1 04-18-2004 02:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration