![]() |
|
|
|
|
|||||||
| 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 |
| how do I make dynamic parameter names? Or get the value of a parameter evaluated twi | Awanka | Shell Programming and Scripting | 2 | 04-19-2007 06:37 PM |
| File Handling in C | trinath | High Level Programming | 3 | 01-19-2006 08:00 PM |
| help in handling loops | borncrazy | Shell Programming and Scripting | 1 | 08-02-2004 02:24 PM |
| exception handling | RichardS | UNIX for Advanced & Expert Users | 1 | 06-16-2004 02:29 PM |
| KSH File Handling | madtim | Shell Programming and Scripting | 2 | 08-27-2002 11:08 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Parameter handling
Hi, i would like to ask that:
If u need to do something like this: counter = 1; so that $($counter) = $1, and when u counter++, $($counter) will become $2. How can we do this? |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
To start with, something like:
eval echo \$$counter will do what you want. But this a terrible way to loop through the parameters. It will not be general. After $9 you be stuck. There is no $10. One way to loop though the parms is #! /usr/bin/ksh for parm ; do echo $parm is a parameter done when you leave off the "in" cause of a "for" statement, you will automatically loop though the parameters. The next way, and the more common solution, is to use the "shift" command. When the script executes a "shift", $1 disappears. And what used to be $2 is now $1 and so on. |
||||
| Google The UNIX and Linux Forums |