The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
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

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-18-2002
Registered User
 

Join Date: Jul 2001
Location: Malaysia
Posts: 21
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  
Old 05-18-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
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
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0