While ...loop | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

While ...loop

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-07-2013
redologger redologger is offline
Registered User
 
Join Date: Jun 2012
Last Activity: 19 October 2013, 2:30 AM EDT
Posts: 11
Thanks: 8
Thanked 0 Times in 0 Posts
While ...loop


Code:
#!/usr/bin/ksh

totalInstance=3
c=1
SID=SID
SID_1=BOYISH
SID_2=EAGALE
SID_3=PLUNE

while [ c -le $totalInstance ]
do
    BDUMP_DIR="${SID}_${c}"
    echo "$BDUMP_DIR"

    c=`expr $c + 1`
    echo "$c"
done

having problem printing the value of my var SID_1, SID_2, SID_3

instead the output printed out is just
SID_1
SID_2
SID_3

i need the value assign to SID_1..3 .
Sponsored Links
    #2  
Old 01-07-2013
Scott's Avatar
Scott Scott is online now Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 24 April 2014, 2:43 PM EDT
Location: in der Schweiz
Posts: 8,322
Thanks: 313
Thanked 1,013 Times in 886 Posts
c is a variable, you need a $ before it.


Code:
while [ "$c" -le ....
 ...
  c=$((c + 1))
...
done

Sponsored Links
    #3  
Old 01-07-2013
rangarasan's Avatar
rangarasan rangarasan is offline
Registered User
 
Join Date: Jul 2011
Last Activity: 11 April 2014, 8:41 AM EDT
Location: Chennai, India
Posts: 494
Thanks: 9
Thanked 124 Times in 120 Posts
Hey,

try this,



Code:
..
while [ $c ...
..

Cheers,
Ranga
    #4  
Old 01-07-2013
redologger redologger is offline
Registered User
 
Join Date: Jun 2012
Last Activity: 19 October 2013, 2:30 AM EDT
Posts: 11
Thanks: 8
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Scott View Post
c is a variable, you need a $ before it.


Code:
while [ "$c" -le ....
 ...
  c=$((c + 1))
...
done

erm..i made the changes u recomanded still not able to get the value assign to SID_1 , SID_2 , SID_3
Sponsored Links
    #5  
Old 01-07-2013
Scott's Avatar
Scott Scott is online now Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 24 April 2014, 2:43 PM EDT
Location: in der Schweiz
Posts: 8,322
Thanks: 313
Thanked 1,013 Times in 886 Posts

Code:
while [ $c -le $totalInstance ]
do
  BDUMP_DIR="${SID}_${c}"
  eval echo "\$$BDUMP_DIR"
  c=$((c + 1))
  echo "$c"
done

The Following User Says Thank You to Scott For This Useful Post:
redologger (01-07-2013)
Sponsored Links
    #6  
Old 01-07-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 23 April 2014, 4:36 AM EDT
Location: Aachen, Germany
Posts: 3,534
Thanks: 51
Thanked 824 Times in 786 Posts
You need either sth corresponding to bash indirection (don't know in ksh - ${!vname}?) or use eval to assign to BDUMP_DIR.
Sponsored Links
    #7  
Old 01-08-2013
redologger redologger is offline
Registered User
 
Join Date: Jun 2012
Last Activity: 19 October 2013, 2:30 AM EDT
Posts: 11
Thanks: 8
Thanked 0 Times in 0 Posts
what happen if is:

Code:
BDUMP_DIR=/home/John/admin/"${SID}_${c}"/bdump

seem like


Code:
eval echo "\$$BDUMP_DIR"

doesn't produce /home/john/admin/plune

---------- Post updated at 09:31 PM ---------- Previous update was at 09:15 PM ----------

Quote:
Originally Posted by redologger View Post
what happen if is:

Code:
BDUMP_DIR=/home/John/admin/"${SID}_${c}"/bdump

seem like


Code:
eval echo "\$$BDUMP_DIR"

doesn't produce /home/john/admin/plune

is ok guys figure it out to be:

Code:
BDUMP_DIR=/home/John/admin/"\$${SID}_${c}"/bdump



---------- Post updated 01-08-13 at 01:48 AM ---------- Previous update was 01-07-13 at 09:31 PM ----------

but i can't figure out why there is a $ infront when i

Code:
eval echo "\$$BDUMP_DIR"

$/home/john/admin/plune


Last edited by Scrutinizer; 01-08-2013 at 02:11 AM..
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Array Variable being Assigned Values in Loop, But Gone when Loop Completes??? mrm5102 Shell Programming and Scripting 5 10-19-2012 10:00 AM
HELP PLS - calling function in a while loop ends the loop ?? newbie_01 Shell Programming and Scripting 3 05-29-2012 04:38 PM
BASH loop inside a loop question rethink Shell Programming and Scripting 4 09-15-2010 07:58 AM
Null Handling in Until loop. . .loop won't stop brandono66 Shell Programming and Scripting 4 11-24-2009 03:57 PM
Using variables created sequentially in a loop while still inside of the loop [bash] DeCoTwc Shell Programming and Scripting 2 06-23-2009 04:59 PM



All times are GMT -4. The time now is 03:12 PM.