|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Search this Thread |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
not bash, using sh. Thanks.
|
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |