Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
google site



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Search this Thread
  #1  
Old 05-19-2009
Registered User
 

Join Date: May 2009
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
passing arguments

Hi
I have a script to which I pass multiple arguments, for example lets say the script name is "abc". I run the script like
./abc def /file <directory location>

In the above "def" is the first argument and "/file" is the second argument. I expect <directory location> that is passed after "/file" not to be an argument but something the is passed if /file is an argument to the script. I currently have a case structure like the below

parseargs ()
{
for i in $CMDLINE_ARGS
do
case $i in
def )
DO_THIS = yes
;;

/file )

;;
}

I basically want the script to read the directory location that is passed and do something with it, without treating it as an argument. I hope my explanation is clear for someone to help me on how I could implement this. Thanks.
Sponsored Links
  #2  
Old 05-19-2009
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 6,772
Thanks: 2
Thanked 67 Times in 62 Posts
read the getopts man page. Traditionally unix command lines look like this

Code:
command -o arg1 -p -q arg2 <arg for command>

Options start with a - and may or may not have arguments, plus they can occur in any order. Hence getopts

getopts tutorial - The 60 second getopts tutorial
  #3  
Old 05-19-2009
Registered User
 

Join Date: May 2009
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Going through the getopts examples, it looks to expect a single character as an option, is that correct? In my case the options are more than a single character as in def hij etc. An example I saw gives something like "while getopts ":mnopq:rs" Option" in my case I beleive I cannot pass something like
"while getopts ":defhij/file:" Option ". Can you pls. clarify? Thanks.
  #4  
Old 05-19-2009
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 6,772
Thanks: 2
Thanked 67 Times in 62 Posts
Are you using bash - it accepts long options with two dashes --thisisalongopt
Options are supposed to have at least one in front of them....
  #5  
Old 05-19-2009
Registered User
 

Join Date: May 2009
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
not bash, using sh. Thanks.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing Arguments-Help Tuxidow Shell Programming and Scripting 5 01-29-2009 08:03 AM
passing strings as arguments iago UNIX for Dummies Questions & Answers 1 08-22-2007 10:04 AM
Passing and using arguments in Scripts. David.Vilmain Shell Programming and Scripting 1 11-13-2006 04:32 PM
Passing arguments to an alias pmcg UNIX for Dummies Questions & Answers 1 10-23-2001 11:15 AM
passing arguments jpprial UNIX for Dummies Questions & Answers 4 04-03-2001 11:13 AM



All times are GMT -4. The time now is 11:12 PM.