I have a string that I pass as a parameter, for example:
"2,3,4,5"
To get every item of it I do:
#!/bin/bash
for ((i=1; i<=4; i++))
do
echo "$1" | cut -d "," -f $i
done
But I would like to make the loop iterate up to the maximum length of the string (which is variable), where each value separated by a comma is an item. So how can I count the number of items to insert into for
?
Example: For "2,3,4,5"
you have 4 items.