You can use ${number[@]:1}
to start iterating from 2nd element:
for i in "${number[@]:1}"; do
echo "Processing: $i"
done
Question
I want to start iterating over the array from the second element for the below array in shell script.
number=${number:-(12 20 43 45 67 40)}
Could you please help me on how to use the For Loop to iterate starting from the second element (ie 20 in this case)
for i in ${number[@]}
Thanks in advance.
Solution
You can use ${number[@]:1}
to start iterating from 2nd element:
for i in "${number[@]:1}"; do
echo "Processing: $i"
done
OTHER TIPS
I usually split the array into $firstLine and $restOfLines like this:
$firstLine, $restOfLines = $sourceArray
foreach($line in $restOfLines) { ... }
See this article: https://devblogs.microsoft.com/powershell/powershell-tip-how-to-shift-arrays/