Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004
    Posts
    7

    Exclamation Unanswered: pointers in SHELL

    #!/bin/bash

    C1=a
    C2=b
    C3=c

    for cnt in 1 2 3
    do
    var=C
    var=$var$cnt
    echo ????
    done


    this is the code i need in a script am at....what i want to print is
    a
    b
    c

    so this is like a pointer in C...how do i do this in my dear UNIX shell

    please help....no, no need of Please and the like....we all are here to help each other...o..o i think u all are here to help me ;-)

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    You must use the eval command
    Code:
    #!/usr/bash
    C1=a
    C2=b
    C3=c
    for cnt in 1 2 3
    do
       var=C$cnt
       eval value=\$$var
       echo $value
       # or
       eval value=\$C$cnt
       echo $value
    done
    Jean-Pierre.

Posting Permissions

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