I have a variable from a previous portion of my script that is greped/sed/cut/sort/uniq from many lines of a previous script output into exactly what i need, n amount of numeric data
echo "$array"
12345
54321
01234
it is my understanding I can treat this column of numbers as an array
the number of items can vary from only 1 to maybe as many as 6. I have verified there is no whitespace that may be throwing things off.
from here i attempt to
for element in "{array[@]}"; do
foo $anothervar "$element"
bar $anothervar "$element"
done
but i end up with all the values in the variable.
foo $anothervar 12345 54321 01234
(please note, $anothervar is just for demonstration purposes, it is actually $1 and so shell expansion of that var isn't necessarily the problem)
and so on. if I
#with double quotes
echo "$element"
12345
54321
01234
#without quotes
echo $element
12345 54321 01234
so I can't do iterative anything with this data. Am I incorrect that I can treat this variable as an array and must perform another action to the var before I can input it to the for loop?
what I am hoping for
foo $anothervar "$element"
*output of $anothervar 12345*
bar $anothervar "$element"
*output of $anothervar 12345*
foo $anothervar "$element"
*output of $anothervar 54321*
bar $anothervar "$element"
*output of $anothervar 54321*
etc etc
This is ksh88 on AIX, from what I have researched this should work, unless possibly ksh88 vs later versions may be involved? I am new to arrays but not new to shell scripting, though I would hardly call myself expert. Thanks in advance for any help provided.
var=...orarray=( ... ... ...)or ?? Edit your Q to show acompletely testable set of data, along with your required output/actions (yes you are close). I would tryfor elem in ${var[@]} ; do...` (no dbl-quotes). Good luck.$var(not an array) ...array[@](looks like an array reference but no idea what's actually inarray[@]) ...$element(not an array); please cleanup the inconsistencies in your post; once you're back to a single variable containing your data, add the output fromtypeset -p <variable_name>to your question so we can see exactly what's in the variable and how it's structured#!/bin/kshor #!/bin/ksh93` as the first line. UPDATE your Q with your best code and required output. Good luck.