The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
comparing PID values of 2 Files in shell Options marconi Shell Programming and Scripting 2 12-19-2007 10:02 AM
Scripts that take String options hanhanbib Shell Programming and Scripting 2 10-18-2007 08:52 PM
Adding PATH variable in the startup scripts rajanishshetty UNIX for Dummies Questions & Answers 5 03-02-2007 09:51 AM
Difference between writing Unix Shell script and AIX Shell Scripts haroonec AIX 0 04-11-2006 11:27 PM
Options for csh shell luiz_fer10 UNIX for Dummies Questions & Answers 10 06-03-2002 01:24 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-21-2005
Registered User
 

Join Date: Feb 2004
Posts: 91
Adding -options to shell scripts

I'm sure this is something simple I am overlooking somehow. I'd like the ability to pass -options into my shell scripts. For example my file called "input.sh" I can do the following:
root# ./input.sh 1

and it will result:
root#./input.sh 1
You passed me a 1

Just like an init script, etc.

I would like to be able to do:
root# ./input -m 1

and have the -m specify a different result in the case statement. Like:

root# ./input.sh -m 1
You passed me a -m 1

#! /bin/bash
case "$1" in
1)
echo "You passed me a 1"
;;
2)
echo "You passed me a 2"
;;
*)
commands;
;;
esac

Thanks for any suggestions as always guys.
Reply With Quote
Forum Sponsor
  #2  
Old 06-21-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
look into 'man getopt'
Reply With Quote
  #3  
Old 06-21-2005
Registered User
 

Join Date: Feb 2004
Posts: 91
Quote:
Originally Posted by vgersh99
look into 'man getopt'
Thank vgersh. This looks pretty gnarly. I will have to poke at it with a stick a bit and see if it moves.
Reply With Quote
  #4  
Old 06-21-2005
google's Avatar
Moderator
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Actually its not that bad. On newer systems, try using getopts. Here is a link that provides an overview and examples for parsing options with case, getopt, and getopts
Reply With Quote
  #5  
Old 06-21-2005
Registered User
 

Join Date: Feb 2004
Posts: 91
Quote:
Originally Posted by google
Actually its not that bad. On newer systems, try using getopts. Here is a link that provides an overview and examples for parsing options with case, getopt, and getopts
Excellent addition google, thank you.

It does indeed seem much more complicated than it really is.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0