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

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!casey!kevinc
  3. From: kevinc@casey.uucp (Kevin C. Castner)
  4. Subject: Setting variables in Bourne Shell
  5. Message-ID: <1992Sep9.154816.24978@casey.uucp>
  6. Keywords: bourne shell
  7. Organization: UPS Research & Development
  8. Date: Wed, 9 Sep 1992 15:48:16 GMT
  9. Lines: 85
  10.  
  11. I am trying to write a shell script that allows me to create a list of
  12. variables in a text file (colon separated) at runtime, and then set the
  13. value to a series of variables.
  14.  
  15. The script looks something like this
  16.  
  17. # VARLIST is really set by a shell process
  18. VARLIST="3 4"
  19.  
  20. for i in `cat ./test.db`
  21. do
  22.     for j in `echo $VARLIST`
  23.     do
  24.         P${j}=`echo $i | cut -f ${j} -d ':'`
  25.     done
  26.  
  27.     echo "P1:${P1}, P2:${P2}"
  28. done
  29.  
  30.  
  31. The test.db is:
  32.  
  33. 11:12:13:14:15:16:17
  34. 21:22:23:24:25:26:27
  35. 31:32:33:34:35:36:37
  36.  
  37. and the output of a sh -x is:
  38.  
  39. VARLIST=3 4
  40. + cat ./test.db 
  41. + echo 3 4 
  42. + echo 11:12:13:14:15:16:17 
  43. + cut -f 3 -d : 
  44. + P3=13 
  45. test.sh: P3=13: not found
  46. + echo 11:12:13:14:15:16:17 
  47. + cut -f 4 -d : 
  48. + P4=14 
  49. test.sh: P4=14: not found
  50. + echo P1:, P2: 
  51. P1:, P2:
  52. + echo 3 4 
  53. + cut -f 3 -d : 
  54. + echo 21:22:23:24:25:26:27 
  55. + P3=23 
  56. test.sh: P3=23: not found
  57. + echo 21:22:23:24:25:26:27 
  58. + cut -f 4 -d : 
  59. + P4=24 
  60. test.sh: P4=24: not found
  61. + echo P1:, P2: 
  62. P1:, P2:
  63. + echo 3 4 
  64. + echo 31:32:33:34:35:36:37 
  65. + cut -f 3 -d : 
  66. + P3=33 
  67. test.sh: P3=33: not found
  68. + echo 31:32:33:34:35:36:37 
  69. + cut -f 4 -d : 
  70. + P4=34 
  71. test.sh: P4=34: not found
  72. + echo P1:, P2: 
  73. P1:, P2:
  74.  
  75.  
  76. It seems as if the assignment is trying to be executed.  I have tried this
  77. on both a Sun OS (4.1.2) and a SCO ODT 1.1 (Sys V 3.2.2) and the problem
  78. is consistent.
  79.  
  80. I don't understand why this is happening.  All I am trying to do is set the
  81. variable.  I think it has something to do with the fact the the variable 
  82. name itself interpreted.  This probably means that it has something to do
  83. with the order of interpretation of the shell.
  84.  
  85. It would be great if someone could explain this to me.
  86.  
  87.  
  88. Thanks
  89.  
  90.  
  91.   ============================================================================
  92.  
  93.     Kevin C. Castner                                 kevinc@ups.com
  94.  
  95.   ============================================================================
  96.