The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
For Loop with Strings as parameters kadishmj Shell Programming and Scripting 6 10-06-2008 04:57 AM
sed and parameters scotty_123 Shell Programming and Scripting 7 03-26-2007 05:22 AM
Need Parameters Help. james2006 Shell Programming and Scripting 3 06-08-2006 11:46 AM
how to get the similar function in while loop or for loop trynew Shell Programming and Scripting 3 06-17-2002 12:09 PM
tar parameters kmar UNIX for Advanced & Expert Users 4 10-23-2001 04:03 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-18-2008
mgirinath mgirinath is offline
Registered User
  
 

Join Date: May 2005
Posts: 69
Parameters in loop

Hi,

I am trying to write a script which will read inputs form user and process those files, I have issue reading the input parameters in a loop. Following is the script...

Code:
I run the script as ./Script.sh 3 table1 table 2 table3

NumberOfTables=$1
let TableCount=1

while [ ${NumberOfTables} -gt 0 ]
do

 TableName='$'$TableCount
 
 db2 "runstats on table ${TableName} and indexes all"

 let  TableCount=TableCount+1
 let  NumberOfTables=NumberOfTables-1

done
exit 0

here I am not able to capture table1 table2 and table3 in the loop it prints TableName as $1 $2 and $3 but not the names that are given as input.

can some one help me on this....
  #2 (permalink)  
Old 03-18-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink Unclear how you are stepping thru variables

Having trouble following your logic, but perhaps the following thoughts will help this move along:
(1) The variable "$#" will be the number of parameters supplied. Thus, perhaps no need for the first 3 after your command because you could skip this and then do NumberOfTables="$#"
(2) The shift function allows a script to keep processing references to $1. Thus, you would do your first set of commands and then do a shift. Shift moves what is in $2 to $1, $3 to $2, etc... ; what was in $1 is now gone.
  #3 (permalink)  
Old 03-18-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink An attempt at some code

I do not think you need the TableCount variable, and perhaps a few other things inside your original code. Hopefully, this will put you on your way...


Code:
> cat script.sh
#! /bin/bash

NumberOfTables="$#"
let TableCount=1

while [ ${NumberOfTables} -gt 0 ]
do

 TableName='$'$TableCount
 
# db2 "runstats on table ${TableName} and indexes all"
# echo ${TableName}
 echo $1
 shift 

 let  TableCount=TableCount+1
 let  NumberOfTables=NumberOfTables-1

done
exit 0

Quote:
> script.sh table1 table2 table3
table1
table2
table3
  #4 (permalink)  
Old 03-18-2008
mgirinath mgirinath is offline
Registered User
  
 

Join Date: May 2005
Posts: 69
Thanks It helped a lot...
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:09 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0