problem in assigning value to variable have value fo other variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem in assigning value to variable have value fo other variable
# 1  
Old 04-25-2012
Error problem in assigning value to variable have value fo other variable

my script is some thing like this

Code:
i11="{1,2,3,4,5,6,7,8,9,10,11,}"

echo "enter value"
read value   ..............suppose i11


x="$value"
echo "$($value)"           .............the echo should be {1,2,3,4,5,6,7,8,9,10,11,}

but its showing "i11" only.

plz help me out to get desired o/p

Last edited by Scrutinizer; 04-25-2012 at 04:06 AM.. Reason: code tags
# 2  
Old 04-25-2012
try execute with same subshell..(read(with pipe) executed normally in separate shell and we can use "(........)" ) for process in the same shell..
(this means --> grouping with parentheses)
Code:
# value=$(echo $i11|(read value;echo $value))

regards
ygemici
This User Gave Thanks to ygemici For This Post:
# 3  
Old 04-25-2012
thanks ygemici,


but problem is something like this

the complete script is



Code:
i1="{01}"
i2="{01,02}"
i3="{01,02,03}"
i4="{01,02,03,04}"
i5="{01,02,03,04,05}"
i6="{01,02,03,04,05,06}"
i7="{01,02,03,04,05,06,07}"
i8="{01,02,03,04,05,06,07,08}"
i9="{01,02,03,04,05,06,07,08,09}"
i10="{01,02,03,04,05,06,07,08,09,10}"
i11="{01,02,03,04,05,06,07,08,09,10,11}"
i12="{01,02,03,04,05,06,07,08,09,10,11,12}"
i13="{01,02,03,04,05,06,07,08,09,10,11,12,13}"
i14="{01,02,03,04,05,06,07,08,09,10,11,12,13,14}"
i15="{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15}"
i16="{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16}"
i17="{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17}"
i18="{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18}"
i19="{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,20}"
i20="{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20}"
i21="{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21}"
i22="{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22}"
i23="{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23}"
i24="{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}"
i25="{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25}"
i26="{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26}"
i27="{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27}"
i28="{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28}"
i29="{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29}"
i30="{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30}"
i31="{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}"

echo -n "ENTER DATE "
read value



x="$value"
echo "$($x)"

this $x should be one value from the above like "{1,2,.......}" as per input

Moderator's Comments:
Mod Comment Welcome to the UNIX and Linux Forums. Please use [code] tags. Video tutorial on how to use them

Last edited by Scrutinizer; 04-25-2012 at 04:08 AM..
# 4  
Old 04-25-2012
I think you should use indirect referencing.

Not sure if this works..Try this..

Code:
 
i11="{1,2,3,4,5,6,7,8,9,10,11,}"
value=i11
eval echo \$$value

# 5  
Old 04-25-2012
this i11 is not fixed its variable from i1 to i31

how to do that....................

Last edited by sagar_1986; 04-25-2012 at 04:30 AM..
# 6  
Old 04-25-2012
what you are trying to achieve ?

is anything related to date calculation?
# 7  
Old 04-25-2012
yes,

if i will enter any date then it should be interpreted as from 01 to that entered date..

suppose its 21 then the interpretation should be 01,....,21

the actual need is

i m passing command though expect for listing specific file/specific pattern from 01 to date entered.
for that command is "ls *{01,02,.....$date}*"
but i m not getting how to send this 01 to $date
if u ll use counter then it will give 1,2,3,....$date
but i want 01,02,..11,12...$date
from 11 onward its ok bt before that 1 to 9 i don't know how to get 01 to 09

---------- Post updated at 02:42 AM ---------- Previous update was at 02:27 AM ----------

Smilie...............
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem assigning cmd output to variable then using in IF statement

Hi, I'm using the bourn shell on a Sun Solaris Unix system. I am relatively new to UNIX scripting so please bear with me... I'm having a couple issues: 1) I need to have a variable $FSIZE set with the output of a command each time the script runs. (the command looks for a file and... (8 Replies)
Discussion started by: dqrgk0
8 Replies

2. Shell Programming and Scripting

problem in assigning variable

suppose in my script i have written a1=2 a2=4 read option # I directly want to see the value of a1 or a2 (i:e; 1 or2 )depending upon i/p given like a1 or a2 to option var.so what should i give .Suppose if I give a1 to option then how can I see the value. echo $$option --- doesn't work pls... (3 Replies)
Discussion started by: maitree
3 Replies

3. Shell Programming and Scripting

problem in assigning substr to a variable inside awk

Hi All, I have a fixed-width datafile from which i need to extract value/string starting from some position to the specified length in each of the lines. awk '{print substr($0,x,y)}' datafile --- is working fine but awk 'BEGIN{a=0}{a=substr($0,x,y);print $a}' datafile ---is giving... (3 Replies)
Discussion started by: loggedin.ksh
3 Replies

4. Shell Programming and Scripting

Removing a character from a variable and assigning it to another variable?

Hi folks. I have this variable called FirstIN that contains something like this: 001,002,003,004... I am trying to assign the content of this variable into ModifiedIN but with the following format : 001 002 003 004...(changing the commas for spaces) I thought about using sed but i am not... (17 Replies)
Discussion started by: Stephan
17 Replies

5. Shell Programming and Scripting

Assigning value to a variable

Is there any difference between: set variable=39 and variable=39 (1 Reply)
Discussion started by: proactiveaditya
1 Replies

6. Shell Programming and Scripting

Assigning value to a variable

can we make a global variable and store character values and add other values to that variable ?? for example a="hello, John" and can we add value ". How are you? so a can have "hello, John. How are you?" can someone help me?? (2 Replies)
Discussion started by: bonosungho
2 Replies

7. Shell Programming and Scripting

Problem with assigning output of grep + awk to a variable

Hi All, I am getting the output for the following command when i run it on the unix console. --------------------------- grep `whoami` /etc/passwd | awk '{print ($1);}' | cut -d ":" -f3 ---------------------------- But i made it into a script and tried to print the variable, its... (5 Replies)
Discussion started by: meheretoknow
5 Replies

8. Shell Programming and Scripting

assigning a variable

hi all, in ksh, how do i assign the output of a find command to a variable, e.g am trying something like this : totalNoFiles=$(print find ./ -name "SystemOut*.log"); but when i echo $totalNoFiles it displays find ./ -name "SystemOut*.log" instead of the total number of... (2 Replies)
Discussion started by: cesarNZ
2 Replies

9. Shell Programming and Scripting

problem assigning values to variable

Date of Request: 20080514 10:37 Submitted By: JPCHIANG i want to get the value "JPCHIANG" only in read a file, however, when i do this: name=`"$line"|cut -d " " -f8` it display all the line and append 'not found' at the end of the statement the $line is actually a variable in a... (2 Replies)
Discussion started by: finalight
2 Replies

10. Shell Programming and Scripting

Assigning a value to variable

Another newbie to Unix scripting Q.. How do you assign a value resulting from a command, such as awk, to a variable. I am currently trying:- $awk '{print $1}' file1 > variable1 with no change to $variable1. The line: $awk '{print $1}' file1 does print the first line of the... (3 Replies)
Discussion started by: sirtrancealot
3 Replies
Login or Register to Ask a Question