Csv-iteration: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(No difference)
|
Latest revision as of 05:19, 25 February 2024
#!/bin/sh
# process a comma-separated list of values
ITEMLIST="apples,pears"
ITEMCOUNT=1
while true
do
ARGCNT="$"
ARGCNT=$ARGCNT$ITEMCOUNT
ITEMNAME=`echo $ITEMLIST | awk -F \, "{print $ARGCNT}"`
if test -z "$ITEMNAME"
then
ITEMCOUNT=$((ITEMCOUNT - 1))
break
else
# item name found, do something with it
echo "Item $ITEMCOUNT = $ITEMNAME"
fi
ITEMCOUNT=$((ITEMCOUNT + 1))
done