Hi, Chris.
Most interpreted languages provide 2 features that control scanning. One is some kind of
escape mechanism that says "don't look at the enclosed text for anything special"; this is often a set of quote marks. The other, often
eval, says "look at this chunk again".
For your code, I added the
eval and an eval of an echo. The
echo, being a print statement, is often your best debugging tool:
Code:
#!/bin/sh
# @(#) s1 Demonstrate eval.
field=""
fieldnumber=0
until [ "$field" = "done" ] ; do
read field
fieldnumber=$((fieldnumber + 1))
eval field$fieldnumber="\"$field\""
eval echo field$fieldnumber="\"$field\""
done
which, when run, produces:
Code:
% ./s1
1
field1=1
2
field2=2
done
field3=done
If you are going to post code here often, please use the CODE tags -- highlight, then click "
#".
For this problem, you might want to consider using an array, q.v.
Best wishes ... cheers, makyo
( edit 1: addition )