You can use ${number[@]:1}
to start iterating from 2nd element:
for i in "${number[@]:1}"; do
echo "Processing: $i"
done
문제
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.
해결책
You can use ${number[@]:1}
to start iterating from 2nd element:
for i in "${number[@]:1}"; do
echo "Processing: $i"
done
다른 팁
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/