-3
#!/bin/bash
channel_name='new1 new2 new3'

for i in $channel_name
do
        eval ${i}_count=1
        echo ${i}_count
done

Output:
new1_count
new2_count
new3_count

I want to display value of new1_count, new2_count etc i.e 1

  • I can somewhat divine what you're asking, but you could make it much easier to grasp your meaning... – DevSolar Feb 04 '15 at 10:06
  • 1
    Various questions (and answers) on this exist, like [this](http://stackoverflow.com/questions/16553089) or [this](http://stackoverflow.com/questions/4385097). Also, searching the web for "bash dynamic variable" yields [this](http://chadsikorra.com/scripting/bash-dynamic-variables). – DevSolar Feb 04 '15 at 10:08
  • 1
    possible duplicate of [Bash dynamic variable names](http://stackoverflow.com/questions/16553089/bash-dynamic-variable-names) – DevSolar Feb 04 '15 at 10:11
  • Instead of jumping on duplicate or this or that. Please have a look on the code. I'm not merging two variables to get a value, I'm trying to fetch value of a variable that is a combination of value of other variable and a text. – Topsy Crests Feb 04 '15 at 10:15
  • Check the last paragraph of the accepted answer of the question linked as duplicate. I tested it, and it works just fine. For your displayed attitude alone, I refuse to post ready-for-use code. – DevSolar Feb 04 '15 at 10:22
  • 1
    If you feel people do not understand your question correctly, you might want to put some more effort in explaining what you want, what you have tried and in what way that didn't work as expected. – fhdrsdg Feb 04 '15 at 10:23

1 Answers1

0

NVM, solved it. Might help others.

#!/bin/bash

channel_name='new1 new2 new3'

for i in $channel_name
do
    eval ${i}_count=1
    echo $((${i}_count))
done