Complex variable assignment


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Complex variable assignment
# 1  
Old 05-05-2011
Complex variable assignment

Hi,
I have a requirement as follows, need to call the format of ${$var} form.

For example, i am taking a variable.
Code:
  count=1, 
  ((LIMIT_$count=$count + 1))

Now i have to echo this variable LIMIT_$count. (This is in a loop..)
echo ${LIMIT_$count} - displays as a syntax error.

Can anyone please help me with this.

Thanks,
Abhishek S.

Moderator's Comments:
Mod Comment Please use [code] and [/code] tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks.

Last edited by zaxxon; 05-05-2011 at 09:24 AM.. Reason: code tags
# 2  
Old 05-05-2011
Code:
count=1
while [ $count -le 10 ]
do
    echo $count
    let count+=1   #or   count=$(( $count + 1 ))
done

# 3  
Old 05-05-2011
I think this is what you want:

Use 'eval'.

Ex:
Code:
#!/usr/bin/ksh93

COUNT=1
eval LIMIT_${COUNT}=$(($COUNT + 1))

echo $LIMIT_1
eval echo \${LIMIT_$COUNT}

Output:

Code:
>
2
2

This User Gave Thanks to purdym For This Post:
# 4  
Old 05-13-2011
MySQL

Hey purdym,
Sorry for the late response, but thats the exact thing i was looking for. Thanks a lot again man.. !! It works for me..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable Assignment

Hi I am facing a problem. export local_folder=/opt/app/ cd /opt/app/abc/ abcversion="abc*" (abcga5 is inside /opt/app/abc/) echo $abcversion (it echoes the correct version as abcga5 ) Now when I reuse the value of abcversion for a below path: export... (6 Replies)
Discussion started by: ankur328
6 Replies

2. Shell Programming and Scripting

Same Variable Assignment

Hi I have a strange problem: In my shell script I am performing a copy task: . prop.txt cp -r $dir/ $dir/archive $dir is fetched from a property file (prop.txt) which stores its value dir=/opt/data Now the problem is another dir1 comes into picture. I only want to add... (1 Reply)
Discussion started by: ankur328
1 Replies

3. Shell Programming and Scripting

Usage of # in assignment of variable

guys, i would like to know what does the below does. tr=`echo $bfile | cut -d"." -f4` tr=${tr#TR} i tried with assigning a value and executed second line. but after that also value of tr remains same. thanks in advance .. (1 Reply)
Discussion started by: expert
1 Replies

4. UNIX for Dummies Questions & Answers

Regex and variable assignment

Hi there, I really didn't want to have to waste people's time and ask this, but after 2 hours and running out of my own time I've decided to ask.. Basically I have a file in the format: word: other words; more words here; last word word: more words here; last word (etc) x 100 Where the... (3 Replies)
Discussion started by: maximus73
3 Replies

5. Shell Programming and Scripting

Help with variable assignment

Hi, In AIX I have a variable with , (coma) separated values assigned to it like shown below var1=apple,boy,chris i want to convert this to var1='apple','boy','chris' the number of values assigned to var1 might change and it could be from 1 to n any suggestions please? (3 Replies)
Discussion started by: rahul9909
3 Replies

6. Shell Programming and Scripting

substituted variable assignment

I try to run this script, however, it gives an exception in line 3. How do I do an assignment to a substituted variable? #!/bin/bash name=fruit ext_$(eval echo ${name})=apple tmp=ext_$(eval echo ${name}) if ]; then echo "apple" elif ]; then echo "orange" fi echo ${!tmp} Error... (2 Replies)
Discussion started by: angelokh
2 Replies

7. Shell Programming and Scripting

eval and variable assignment

Hi, i have an issue with eval and variable assignment. 1) i have a date value in a variable and that date is part of a filename, var1=20100331 file1=${var1}-D1-0092.xml.zip file2=${var2}-D2-0092.xml.zip file3=${var3}-D3-0092.xml.zip i am passing the above variables to a script via... (11 Replies)
Discussion started by: mohanpadamata
11 Replies

8. Shell Programming and Scripting

Dynamic variable assignment

Hi All, I have the below scenario: A file test.cfg with three fields>> DATA1 DATA2 DATA3 In the script I need to assign each of the fields to variables. The number of fields will not be constant (this case we have three). Im trying to do something like this: NUM=1 OUT_DAT_NO=3 ... (4 Replies)
Discussion started by: deepakgang
4 Replies

9. UNIX for Dummies Questions & Answers

Variable assignment problem

Hi, I am having a problem with assigning a value to a variable. The empname is looked for in the employees file and I am trying to assign it to the jobnum variable in the following statement jobnum= cat/etc/employees | grep $empname | cut -d : -f 5 It is getting the right answer but it is... (3 Replies)
Discussion started by: rodney08
3 Replies

10. UNIX for Dummies Questions & Answers

@ in a variable assignment

Hello Everybody, Does anyone know what the @ symbol means in a csh script, if used with a variable assignment as below @ line = 1 why not just use.... set line=1 Many thanks rkap (1 Reply)
Discussion started by: rkap
1 Replies
Login or Register to Ask a Question