I have checked Looping over arrays, printing both index and value. The issue is I want to loop over output of command and not an array.
The code i came up with is:
array=($(seq 1 10))
for i in "${!array[@]}"; do
printf "%s\t%s\n" "$i" "${array[$i]}"
done
or,
ITER=0
for I in $(seq 1 10)
do
echo ${I} ${ITER}
ITER=$(expr $ITER + 1)
done
What i want to know is, is it possible to do it within the loop only (without array
or ITER
) outside the loop?
What i am looking for is something like:
for index,value in $(seq 1 10); do
echo $index $value
done