|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | 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. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Optional Parameters/arguments while executing a script.
Hello, I have a shell script "Test.ksh" and I need to pass 8 parameters/arguments while executing the script Code:
./Test.ksh 1 2 3 4 5 6 7 8 Out of these I want first 3 to be compulsory and rest 5 to be optional. Can you suggest the way to do this like and also how to pass these optional arguments like Is it Code:
./Test.ksh 1 2 3 4 7 8 #OR... ./Test.ksh 1 2 3 4 <space> <space> 7 8 or any other??? Last edited by Scott; 09-03-2010 at 02:40 PM.. Reason: Please use code tags |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
Hi. Code:
if [ $# -lt 3 ]; then echo "not enough arguments..." ... fi You can have as many spaces as you like between arguments. I would suggest looking at getopts. |
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
Hello..
Thanks for the quicky.. Will "if [ $# -lt 3 ]" check for case when any 3 arguments are passed or the first 3. |
|
#4
|
||||
|
||||
|
Hi.
It will check that three arguments are passed. It will not tell you if arguments 1, 2 and 3, or 1, 4 an 7 are passed, as you think of them. I would suggest you use getopts. |
| 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 |
| executing perl with arguments in tcl | sukrish | Shell Programming and Scripting | 0 | 08-24-2010 04:49 AM |
| tar cmd how many arguments into parameters of filenames | presul | Shell Programming and Scripting | 1 | 06-15-2010 05:02 AM |
| How to make parameters optional? | neeto | Shell Programming and Scripting | 2 | 05-23-2008 11:57 PM |
| help me in sending parameters from sqlplus script to unix shell script | Hara | Shell Programming and Scripting | 2 | 01-29-2008 02:31 PM |
| Passing variables/arguments/parameters to commands | Perderabo | Answers to Frequently Asked Questions | 0 | 06-13-2004 07:37 PM |
|
|