The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 01:02 PM
Scripts that take String options hanhanbib Shell Programming and Scripting 2 10-18-2007 11:52 PM
Adding PATH variable in the startup scripts rajanishshetty UNIX for Dummies Questions & Answers 5 03-02-2007 12:51 PM
Difference between writing Unix Shell script and AIX Shell Scripts haroonec AIX 0 04-12-2006 02:27 AM
Options for csh shell luiz_fer10 UNIX for Dummies Questions & Answers 10 06-03-2002 04:24 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-21-2005
sysera sysera is offline
Registered User
  
 

Join Date: Feb 2004
Posts: 92
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.
  #2 (permalink)  
Old 06-21-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
look into 'man getopt'
  #3 (permalink)  
Old 06-21-2005
sysera sysera is offline
Registered User
  
 

Join Date: Feb 2004
Posts: 92
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.
  #4 (permalink)  
Old 06-21-2005
google's Avatar
google google is offline Forum Advisor  
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
  #5 (permalink)  
Old 06-21-2005
sysera sysera is offline
Registered User
  
 

Join Date: Feb 2004
Posts: 92
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:12 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0