LinuxQuestions.org
Review your favorite Linux distribution.
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-19-2006, 02:06 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
Your help


I ran the following program. I don't understand some of it.

#!/bin/sh
case $1 in
--test|-t)
echo "you used the --test option"
exit 0
;;
--help|-h)
echo "Usage:"
echo " myprog.sh [--test|--help|--version]"
exit 0
;;
--version|-v)
echo "myprog.sh version 0.0.1"
exit 0
;;
-*)
echo "No such option $1"
echo "Usage:"
echo " myprog.sh [--test|--help|--version]"
exit 1
;;
esac

echo "You typed \"$1\" on the command-line"

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

Do I need a program called '' myprog.sh '' to run this program?

I got the following message when running it.

You typed "" on the command-line.

The name of the program is '' temp25 '' .


[nissanka@c83-250-111-20 ~]$ chmod 755 temp25
[nissanka@c83-250-111-20 ~]$ ./temp25
You typed "" on the command-line

--------------------------------------------------
I have a file called '' Cisco ''

[nissanka@c83-250-111-20 ~]$ ./temp25 Cisco
You typed "Cisco" on the command-line
[nissanka@c83-250-111-20 ~]$


Could you please tell me how to run this program and how it works?
 
Old 03-19-2006, 02:20 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
please use suitable thread titles in future. i'd suggest reading the bash scripting howto to actually understand what's going on there. if you don't know bash, i don't see why you'd need to know what this even does... it's just some example script for using a case statement. it doesn't "do" anything, and myprog.sh is just what the example file itself would be called.
 
Old 03-19-2006, 02:43 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi, Gins -

Like acid_kepie said, the script you found, "temp25", is just an example that shows you how to parse command line parameters from a shell script. It doesn't actually "do" anything (except, of course, echo back the parameters you typed in).

Not only that, but the method they use for parsing the command lnie parameters (a shell "case" block) isn't even the only way to do it. Or even the best way (for example, that particular case switch might crash if you don't type in any arguments).

'Hope that helps ...
 
Old 03-19-2006, 03:41 PM   #4
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
I thank both of you for the replies.

acid_kewpie, what do you mean by a suitable title here?
 
Old 03-19-2006, 04:08 PM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
what is "your help" supposed to mean?? what was wrong with somethign useful like "What does this example bash script do?" or something??
 
Old 03-19-2006, 04:57 PM   #6
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 acid_kewpie

I am learning those scripting using some online resources nowadays. I will be posting more questions. I would try to write sensible heading which fullfills your requirement.

Those scripting is a tall order to me.
 
  


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



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

All times are GMT -5. The time now is 05:57 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