Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

While ...loop

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-07-2013
redologger redologger is offline
Registered User
 
Join Date: Jun 2012
Last Activity: 16 June 2014, 10:28 PM EDT
Posts: 14
Thanks: 12
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 Unix and Linux 01-07-2013
Scott's Unix or Linux Image
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 1 September 2015, 7:26 AM EDT
Location: Zürich
Posts: 8,575
Thanks: 337
Thanked 1,080 Times in 938 Posts
c is a variable, you need a $ before it.


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

Sponsored Links
    #3  
Old Unix and Linux 01-07-2013
rangarasan's Unix or Linux Image
rangarasan rangarasan is offline
Registered User
 
Join Date: Jul 2011
Last Activity: 1 July 2015, 11:47 AM EDT
Location: Chennai, India
Posts: 496
Thanks: 9
Thanked 124 Times in 120 Posts
Hey,

try this,



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

Cheers,
RangaLinux
    #4  
Old Unix and Linux 01-07-2013
redologger redologger is offline
Registered User
 
Join Date: Jun 2012
Last Activity: 16 June 2014, 10:28 PM EDT
Posts: 14
Thanks: 12
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 Unix and Linux 01-07-2013
Scott's Unix or Linux Image
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 1 September 2015, 7:26 AM EDT
Location: Zürich
Posts: 8,575
Thanks: 337
Thanked 1,080 Times in 938 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 Unix and Linux 01-07-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 1 September 2015, 2:57 AM EDT
Location: Aachen, Germany
Posts: 6,608
Thanks: 113
Thanked 1,811 Times in 1,697 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 Unix and Linux 01-08-2013
redologger redologger is offline
Registered User
 
Join Date: Jun 2012
Last Activity: 16 June 2014, 10:28 PM EDT
Posts: 14
Thanks: 12
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

Linux

---------- 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 10:08 AM.