![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Calling sql in shell script with parameters | Radhe | Shell Programming and Scripting | 2 | 04-21-2008 09:27 AM |
| How to pass two or more parameters to the main in shell script | pinky | UNIX for Dummies Questions & Answers | 0 | 10-12-2007 08:54 AM |
| Call a UNIX shell with parameters from C | dustman | UNIX for Dummies Questions & Answers | 1 | 03-14-2007 07:26 PM |
| Max number of parameters to korn shell? | rajus19 | Shell Programming and Scripting | 4 | 02-03-2006 06:01 AM |
| Number of parameters to a shell script | videsh77 | Shell Programming and Scripting | 1 | 05-13-2005 07:39 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
I need to check the number of input parameters in the K shell script.
Also, I want to exit if the no of parameters is not met. How can I do that ? Thanks LS1429 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
I think I see what you mean... For example, the command:
myscript.ksh -a 1 -q has 3 input parameters... Am I correct? If so, you can use $# to count them. Here is an example: Code:
#!/usr/bin/ksh
if [ "$#" = "0" ]; then
echo "You don't have any arguments! "; exit
fi
echo $#
chmod +x scriptname ./scriptname ./scriptname 1 b 3 d See what happens. If you have any more questions, please feel free to post back. I hope I got what you were asking. |
|
#3
|
|||
|
|||
|
Shell Parameters
Yeah thatz it.
One more thing. But I am not clear why the ; after condition is really needed or not if [ $# -ne 1 ] then echo "Provide one Parameter " exit 1 fi Thanks LS1429 |
|
#4
|
||||
|
||||
|
Re: Shell Parameters
Quote:
date who or we can enter both commands on a single line if we use the semicolon like this: date ; who But we gotta have something separating the two commands. Usually we have the newline character as the delimiter between commands, but the semicolon also works. So it's a matter of style whether you use if [ ... ] ; then or if [ ... ] then I like the first style because it lets more of the script be visible on a page. But I wouldn't call the second style "wrong". |
||||
| Google The UNIX and Linux Forums |