Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2008
    Posts
    7

    Unanswered: How to concatenate a string and a variable

    I need a way to build variable in this manner:

    variable_$i
    Inside a for loop i need to create it.
    where i goes from 1 to 30..
    and then i need to print them on screen with echo $variable_$i
    which is the best way to do this?

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Is this the sort of thing you're after ?
    Code:
    #!/bin/sh
    
    variable_1="testa"
    variable_2="testb"
    variable_3="testc"
    
    for i in 1 2 3
    do
            eval echo '$variable_'$i
    done
    
    exit 0
    Mike

Posting Permissions

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