In bash it's quite easy. Just execute the "set" command with you list-variable. You can then acces them with $1, $2, $3, ... or iterate through them using the "shift" command. Of course the original contents of $1, $2,... (the script arguments) are lost. But you can save them before in seperate var's, or in just one var, e.g: SAVED_ARGS=$* and then restore the arguments with "set $SAVED_ARGS" later on.
Demo:
Code:
#!/bin/bash
# We are going to lose the arguments passed to the this
# script. So store them in other var's before.
LIST="3 76 23 22 345 22 1 9 8 6 3 3 3 2 2 1"
# Set the items in the postitional parameters ($1, $2, $3, ...)
# If the list is comma-seperated, you need to set the IFS var to a comma
# before the set command. E.g: IFS=,
set $LIST
# Now the original argument to the script have disappeared.
# They have been replaced by the items from $LIST
echo $1
echo $2
echo $3
echo $4
echo $5
echo $6
echo $7
echo $8
echo $9
echo ${10} # When you need two digits, curly braces are needed.
echo ${11}
echo ${12}
echo ${13}
echo ${14}
echo ${15}
echo ${16}
echo ${17}
echo ==============================
# Or you can iterate through them, with shift.
# After a shift:
# $1 becomes $2
# $2 becomes $3
# ...and so on. ($0 is not touched by shift)
echo $1
while shift ; do
echo $1
done