LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-25-2003, 08:04 PM   #1
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Rep: Reputation: 47
Shell script


I am making a shell script, I was wondering if I could get a brief howto or link to one that explains how you can do the following:

name.sh --prefix=whatever

and then have the prefix variable set

basically what do I put in the shellscript for it to recognise the --prefix command line option?
 
Old 08-25-2003, 08:45 PM   #2
AltF4
Member
 
Registered: Sep 2002
Location: .at
Distribution: SuSE, Knoppix
Posts: 532

Rep: Reputation: 31
"man getopt" should answer your questions how to parse parameters
 
Old 08-25-2003, 08:55 PM   #3
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Original Poster
Rep: Reputation: 47
thanks, this will help a lot.
 
Old 08-25-2003, 09:22 PM   #4
slapNUT
Member
 
Registered: Jun 2001
Location: Recycle Bin
Distribution: Linux & Everything else on VirtualBox
Posts: 144

Rep: Reputation: 15
I don't remember where I found this but I like to start all my scripts this way. I gives you a good starting point. I added the --prefix= but you can add as many options as you like this way.

Code:
!/bin/bash

function usage ()
{
       echo "Usage:"
       echo "        script [--test|--help|--version] [--prefix=<prefix>]"
}

while test "$1" != "" ; do
        case $1 in
                --prefix=*)
                        prefix=`echo $1|sed 's/^.*\=//'`
                        echo "Prefix set to $prefix"
                ;;
                --test|-t)
                        echo "you used the --test option"
                ;;
                --help|-h)
                        usage
                        exit 0
                ;;
                --version|-v)
                        echo "script version 0.0.1"
                        exit 0
                ;;
                -*)
                        echo "Error: no such option $1"
                        usage
                        exit 1
                ;;
        esac
        shift
done

Last edited by slapNUT; 08-25-2003 at 09:26 PM.
 
Old 08-25-2003, 09:25 PM   #5
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Original Poster
Rep: Reputation: 47
that is great, thanx a lot!
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script inside shell script treotan Linux - General 4 02-19-2009 06:34 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
[SHELL SCRIPT] Write at the right of the shell window Creak Linux - General 2 04-02-2004 03:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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