Some one look into this


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Some one look into this
# 1  
Old 04-29-2011
Some one look into this

Code:
$ export ABC1=/my/dir
$ export t=2
$ echo $ABC1
/my/dir
$ echo $ABC$t
2
$ echo $ABC${t}
2

I tried different ways but couldnet get expected result...
can some one let me know where am wrong and what would i need to type to get correct output by giving variable t

Last edited by Scott; 04-30-2011 at 11:40 AM.. Reason: Code tags
# 2  
Old 04-30-2011
works as expected:

Code:
echo $ABC1$t

# 3  
Old 04-30-2011
it doesnt work
...
see if have ABC2 =/my/dir/abc
ABC3=/export/apps/
then how would you get all three
do you write
echo $ABC1$t ...?
will it work...

please give me possible solution
so that i neet to get the output with variable
# 4  
Old 04-30-2011
It's not exactly clear, but maybe you need eval?

i.e.
Code:
$ ABC1=/my/dir
$ t=1
$ eval echo \$ABC$t
/my/dir

# 5  
Old 04-30-2011
I tried the solution you passed .. it works .. but i need to use it in other format i.e
Code:
export ABC1=/my/dir1
export ABC2=/my/dir2
export ABC3=/my/dir3
for i in 1 2 3
do
echo $ABC$i
mkdir -p $ABC$i
done

it fails.... can you please point my error

Last edited by maddyfreaks; 04-30-2011 at 06:22 PM..
# 6  
Old 04-30-2011
Code:
export ABC1=/my/dir1
export ABC2=/my/dir2
export ABC3=/my/dir3
for i in 1 2 3
do
echo $ABC$i
mkdir -p $ABC$i
done

# 7  
Old 04-30-2011
It doesnt work.... any ideas are welcome
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question