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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[: too many arguments tainted2real Shell Programming and Scripting 4 08-26-2008 05:25 AM
getopts with non-option arguments? kdelok Shell Programming and Scripting 2 07-26-2008 11:44 PM
awk arguments karthikn7974 Shell Programming and Scripting 6 05-07-2008 01:34 AM
option followed by : taking next option if argument missing with getopts gurukottur Shell Programming and Scripting 2 03-17-2008 12:46 PM
several arguments together homefp Shell Programming and Scripting 8 07-04-2002 04:44 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-24-2009
esia esia is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 1
Getting 2 or more arguments from an option

Hi. Is there a way I can get 2 or more arguments from an option?

Something like:

Usage: myscript -a arg1 arg2

Then a simple printing of arg1 and arg2 will do. I just need it as a template. The script should also work if no arguments for option "a" is specified. so running "myscript -a" will still do something.

I've tried using the getopts command but I can only seem to handle arg1.

Thanks in advance.

Last edited by esia; 02-24-2009 at 11:57 PM..
  #2 (permalink)  
Old 03-05-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,886

Code:

while [ x"$1" != x -a x"${1#-}" != x"$1" ]; do 
   case "$1" in 
   -a)  opta="$2 $3"; shift 3; ;;
   -*)  echo "Unknown option: $1"; shift ;;
   esac
done
echo $opta

Closed Thread

Bookmarks

Tags
parsing options

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 06:23 PM.


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