Find the answer to your Linux question:
Results 1 to 2 of 2
x=1 c1=string1 c2=string2 c3=string3 echo c$x c1 I'd like to have the output be string1 by entering something like: echo $(c$x) can someone point me in the right direction....
  1. #1
    Just Joined!
    Join Date
    Feb 2005
    Posts
    14

    bash variable inside variable

    x=1
    c1=string1
    c2=string2
    c3=string3

    echo c$x
    c1

    I'd like to have the output be string1 by entering something like:
    echo $(c$x)

    can someone point me in the right direction.

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Use eval, something like:

    Code:
    x=1
    c1=string1
    
    eval "var=\$c${x}"
    
    echo $var

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...