home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / shell / 3867 < prev    next >
Encoding:
Text File  |  1992-09-09  |  1.2 KB  |  48 lines

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!caen!destroyer!ubc-cs!dhami
  3. From: dhami@cs.ubc.ca (Mandeep S Dhami)
  4. Subject: Re: Setting variables in Bourne Shell
  5. Message-ID: <1992Sep9.171034.17588@cs.ubc.ca>
  6. Keywords: bourne shell
  7. Sender: usenet@cs.ubc.ca (Usenet News)
  8. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  9. References: <1992Sep9.154816.24978@casey.uucp>
  10. Date: Wed, 9 Sep 92 17:10:34 GMT
  11. Lines: 35
  12.  
  13. kevinc@casey.uucp (Kevin C. Castner) writes:
  14.  
  15. ># VARLIST is really set by a shell process
  16. >VARLIST="3 4"
  17.  
  18. >for i in `cat ./test.db`
  19. >do
  20. >    for j in `echo $VARLIST`
  21. >    do
  22. >        P${j}=`echo $i | cut -f ${j} -d ':'`
  23.           --->  ^^^^
  24. >    done
  25.  
  26. >    echo "P1:${P1}, P2:${P2}"
  27.  
  28. >done
  29.  
  30.  
  31. Use eval. You can not assign to $variable, but you may eval
  32. such a string. To give you an example:
  33. # X=A 
  34. # Y=B
  35. # $X=$Y
  36. A=B: not found  # Same problem as yours, 
  37. # eval $X=$Y    # The Solution
  38. # echo $A
  39. B
  40.  
  41.  
  42. Mandeep
  43. __________________________________________________________________
  44. "I'm very brave generally," he went on in a low voice:
  45. "only to-day I happen to have a headache."
  46.                                       -- Lewis Carroll
  47. __________________________________________________________________
  48.