David Powell wrote:
>
> I have a shell script that uses 'read' to populate an array element
> by element. However, if my array is named "array" and I'm reading
> into index X, and there is a file in the current working directory
> called "arrayX", it malfunctions. I've reduced it to the following
> test case:
>
> #!/bin/ksh
>
> rm -f list0 2>/dev/null
>
> unset list
> set -A list
> echo foo | read list[0]
> echo "list[0]: ${list[0]}"
> echo "list0: ${list0}"
>
> touch list0
>
> unset list
> set -A list
> echo foo | read list[0]
> echo "list[0]: ${list[0]}"
> echo "list0: ${list0}"
>
> Which emits:
>
> list[0]: foo
> list0:
> list[0]:
> list0: foo
>
> I'm baffled.
Erm... without testing I guess you hit filename globbing in this case.
You create a file "list0" which matches the shell pattern "list[0]" and
therefore the 2nd read will hit a different name as array name.
There are two fixes:
a) Use $ set -o noglob # to disable filename globbing
b) Use quotes around variable names which access array elements, e.g. $
echo foo | read 'list[0]' # in the example above.
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)