The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
getting variable inside awk subin_bala Shell Programming and Scripting 1 06-05-2008 04:21 AM
variable part of variable name Smoker Shell Programming and Scripting 2 01-25-2008 01:11 PM
passing a variable inside a variable to a function KingVikram UNIX for Dummies Questions & Answers 2 01-14-2008 08:28 PM
How to replace variable inside the variable mani_um Shell Programming and Scripting 31 08-09-2007 10:56 PM
variable inside awk '{print $c}' Tártaro Shell Programming and Scripting 3 04-13-2007 08:22 AM

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

Join Date: Mar 2005
Posts: 3
ksh: A part of variable A's name is inside of variable B, how to update A?

This is what I tried:

vara=${varb}_count
(( vara += 1 ))


Thanks for help
  #2 (permalink)  
Old 03-28-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Quote:
Originally Posted by pa3be
This is what I tried:

vara=${varb}_count
(( vara += 1 ))


Thanks for help
hmm.... this is one confusing explanation.
what are you trying to do?
  #3 (permalink)  
Old 03-28-2005
pa3be pa3be is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 3
I'm iterating through a list of test names, each has two associated variables: the number of times the test passed, and the number of times the test ran

varb would be the name of the test at the current iteration (e.g. test04)

when I check if the test passed, I need to increment the corresponding count variable (for example, if at this iteration the test name is test04, the associated count variable name is test04_count)

Thus, the name of the variable to be incremented is composed from the value of one variable (varb) and "_count"

The question is how to increment that variable (vara)
  #4 (permalink)  
Old 03-28-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
here's something to start with as I'm still a bit confused....

Code:
#!/bin/ksh

typeset num;

for iter in 1 2 3 4 5 6 7 15 123
do
   varb="test$(printf "%02d" ${iter})"
   vara="${varb}_count"
   # increment vara
   #
   num=$(printf "%02d" $(( $(echo "${vara}" | sed -e 's/^[^0-9]*\([0-9][0-9]*\)_.*/\1/') + 1 )) )
   echo "varb->[${varb}] vara->[${vara}] incrementedNum->[${num}] incrementedVarA->[test${num}_count]"
done;

Last edited by vgersh99; 03-28-2005 at 05:21 PM..
  #5 (permalink)  
Old 03-30-2005
pa3be pa3be is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 3
after some adjustments, I got what I needed.

Thanks a lot.
Sponsored Links
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 12:30 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