home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!casey!kevinc
- From: kevinc@casey.uucp (Kevin C. Castner)
- Subject: Setting variables in Bourne Shell
- Message-ID: <1992Sep9.154816.24978@casey.uucp>
- Keywords: bourne shell
- Organization: UPS Research & Development
- Date: Wed, 9 Sep 1992 15:48:16 GMT
- Lines: 85
-
- I am trying to write a shell script that allows me to create a list of
- variables in a text file (colon separated) at runtime, and then set the
- value to a series of variables.
-
- The script looks something like this
-
- # VARLIST is really set by a shell process
- VARLIST="3 4"
-
- for i in `cat ./test.db`
- do
- for j in `echo $VARLIST`
- do
- P${j}=`echo $i | cut -f ${j} -d ':'`
- done
-
- echo "P1:${P1}, P2:${P2}"
- done
-
-
- The test.db is:
-
- 11:12:13:14:15:16:17
- 21:22:23:24:25:26:27
- 31:32:33:34:35:36:37
-
- and the output of a sh -x is:
-
- VARLIST=3 4
- + cat ./test.db
- + echo 3 4
- + echo 11:12:13:14:15:16:17
- + cut -f 3 -d :
- + P3=13
- test.sh: P3=13: not found
- + echo 11:12:13:14:15:16:17
- + cut -f 4 -d :
- + P4=14
- test.sh: P4=14: not found
- + echo P1:, P2:
- P1:, P2:
- + echo 3 4
- + cut -f 3 -d :
- + echo 21:22:23:24:25:26:27
- + P3=23
- test.sh: P3=23: not found
- + echo 21:22:23:24:25:26:27
- + cut -f 4 -d :
- + P4=24
- test.sh: P4=24: not found
- + echo P1:, P2:
- P1:, P2:
- + echo 3 4
- + echo 31:32:33:34:35:36:37
- + cut -f 3 -d :
- + P3=33
- test.sh: P3=33: not found
- + echo 31:32:33:34:35:36:37
- + cut -f 4 -d :
- + P4=34
- test.sh: P4=34: not found
- + echo P1:, P2:
- P1:, P2:
-
-
- It seems as if the assignment is trying to be executed. I have tried this
- on both a Sun OS (4.1.2) and a SCO ODT 1.1 (Sys V 3.2.2) and the problem
- is consistent.
-
- I don't understand why this is happening. All I am trying to do is set the
- variable. I think it has something to do with the fact the the variable
- name itself interpreted. This probably means that it has something to do
- with the order of interpretation of the shell.
-
- It would be great if someone could explain this to me.
-
-
- Thanks
-
-
- ============================================================================
-
- Kevin C. Castner kevinc@ups.com
-
- ============================================================================
-