LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 03-21-2006, 02:02 PM   #1
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662

Rep: Reputation: 47
I can't fathom the program


#!/bin/sh

case $1 in

aa|ab) echo A

;;

b?) echo "B \c"

echo $1;;

c*) echo C;;

*) echo D;;

esac

--------------------------

I ran this program. It just give me the word '' D ''.

This program is to learn how the '' case ' works.

What is '' aa|ab) echo A '' ?


What is ' esac ' stands for?
Could you tell how to run this?
I urge you to tell me the way this progrma works.
-------------------------------------------------------------------------

[nissanka@c83-250-108-234 ~]$ vi temp28
[nissanka@c83-250-108-234 ~]$ chmod 755 temp28
[nissanka@c83-250-108-234 ~]$ ./temp28
D




[nissanka@c83-250-108-234 ~]$ ./temp28 A
D

[nissanka@c83-250-108-234 ~]$ ./temp28 C
D

[nissanka@c83-250-108-234 ~]$ ./temp28 B
D

[nissanka@c83-250-108-234 ~]$ ./temp28 D
D

[nissanka@c83-250-108-234 ~]$ ./temp28 E
D

[nissanka@c83-250-108-234 ~]$ ./temp28 F
D

[nissanka@c83-250-108-234 ~]$ ./temp28 aa
A

[nissanka@c83-250-108-234 ~]$
 
Old 03-21-2006, 02:18 PM   #2
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
Quote:
What is '' aa|ab) echo A '' ?
If $1 (the first commandline parameter sent to the script) is "aa" or "ab", then it will echo "A".
b? checks for a lowercase "b" followed by a single character (b5, for example, would work, but b52 would not).
c* checks for a lowercase "c" followed by anything, or "c" followed by nothing.
* is a catch-all...if none of the previous were found, it uses this option.

You received "D" as the output because you either supplied no parameters, or provided a parameter that was not listed within the case command.
You should see from your tests that the only time you did not get a "D" was when you ran "temp28 aa", which is one of the options listed in the case command.

Last edited by mikshaw; 03-21-2006 at 02:19 PM.
 
Old 03-21-2006, 02:32 PM   #3
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662

Original Poster
Rep: Reputation: 47
Thanks mikshaw

Now I understand. I am trying to learn; so your help is badly needed.

By the way, the letters '' fi '' terminates a program.

I guess '' fi '' stands for finish.

Here it is '' esac ''. What is it?

Last edited by Gins; 03-21-2006 at 02:35 PM.
 
Old 03-21-2006, 02:35 PM   #4
rshaw
Senior Member
 
Registered: Apr 2001
Location: Perry, Iowa
Distribution: Mepis , Debian
Posts: 2,692

Rep: Reputation: 45
esac is "case" backwards it closes the case statement. just as "fi" is used to close an "if"
 
Old 03-21-2006, 02:37 PM   #5
geeman2.0
Member
 
Registered: Feb 2005
Location: Ontario, Canada
Distribution: Gentoo, Slackware
Posts: 345

Rep: Reputation: 30
fi usually terminates an "if" statement block.
I'd always assumed it was because "fi" = "if" spelt backwards.
There can be multiple fi's in a program, so it does not terminate the program.
 
  


Reply



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
sms program and database in linux web program in windows.. does not see each other.. keikun_naruchan Programming 0 07-06-2005 01:40 AM
Total recovery: Which program? ghost4linux, YaST2? Best drive imaging program? lagu2653 Linux - Software 1 06-20-2005 01:44 PM
Stop java program(threaded program..should end cleanly) rmanocha Programming 4 11-09-2004 09:36 AM
Gtk-Warning but program still works... I close konsole, program closes Laptop2250 Linux - Software 2 11-14-2003 11:18 PM
Trying to fathom Smasung SM-308B under Mandrake 9.0 Cadmus Linux - Hardware 1 04-09-2003 08:41 AM

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

All times are GMT -5. The time now is 05:03 PM.

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