-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

6
  • I can somewhat divine what you're asking, but you could make it much easier to grasp your meaning... Commented Feb 4, 2015 at 10:06
  • 1
    Various questions (and answers) on this exist, like this or this. Also, searching the web for "bash dynamic variable" yields this. Commented Feb 4, 2015 at 10:08
  • 1
    possible duplicate of Bash dynamic variable names Commented Feb 4, 2015 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. Commented Feb 4, 2015 at 10:15
  • 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. Commented Feb 4, 2015 at 10:23

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.