문제

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/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top