Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

While ...loop

Shell Programming and Scripting


Closed    
 
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: 7 December 2016, 12:24 PM EST
Location: Zürich
Posts: 8,598
Thanks: 343
Thanked 1,093 Times in 949 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: 28 November 2016, 9:58 AM EST
Location: Chennai, India
Posts: 509
Thanks: 16
Thanked 131 Times in 127 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: 7 December 2016, 12:24 PM EST
Location: Zürich
Posts: 8,598
Thanks: 343
Thanked 1,093 Times in 949 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 online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 8 December 2016, 4:41 AM EST
Location: Aachen, Germany
Posts: 9,927
Thanks: 200
Thanked 2,952 Times in 2,753 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 03:11 AM..
Sponsored Links
Closed

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 11:00 AM
BASH loop inside a loop question rethink Shell Programming and Scripting 4 09-15-2010 08:58 AM
Null Handling in Until loop. . .loop won't stop brandono66 Shell Programming and Scripting 4 11-24-2009 04: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 05:59 PM



All times are GMT -4. The time now is 05:46 AM.