이 기능이 멈춘 이유를 알 수 없습니다.
내가하려는 것은 미리 결정된 시작 날짜부터 현재 달까지 폴더를 만드는 것입니다. 불행히도 모든 폴더 생성을 완료 한 다음 아래에 게시 된 산술에 갇혀 있습니다.
누구든지 올바른 길로 갈 수 있도록 힌트를 줄 수 있습니까?
내 코드는 다음과 같습니다.
yearloop(){
year=$(echo "$firstmsgdate"|cut -d"/" -f3)
zmmailbox -z -m $account gf /archive || zmmailbox -z -m $account cf /archive
crntmnth=$(date +"%m")
incmonth=0
while [ $year -le $currentyear ]; do
if [ "$year" -lt "$currentyear" ]; then
#do stuff
let year++
elif [ $year -eq $currentyear ]; then
while [ $incmonth -lt $crntmnth ]; do
#do otherthings
let incmonth++
done
else
echo "Else"
fi
done
}
이것은 내가받는 출력이다
+ '['15 -le 15 ']'
+ '['15 -lt 15 ']'
+ '['15 -eq 15 ']'
+ '['2 -lt 02 ']'
+ '['15 -le 15 ']'
+ '['15 -lt 15 ']'
+ '['15 -eq 15 ']'
+ '['2 -lt 02 ']'
+ '['15- 르 15 ']'
연도가 현재 연도에 도달하면 다시 증가하지 않으므로 ( elif
적용 중) while
"작거나 같음"을 테스트 하는 외부 루프가 여전히 유효합니다. 부품 let year++
의 while
루프 뒤에 넣으면 elif
작동합니다. 또는 더 나은 방법 ... break
그 시점에서 명시 적으로 전화하십시오 . while
자체적으로 종료하기 위해 루프에 의존하는 것은 결코 좋지 않습니다 .
또한 시퀀스를 사용하고 모든 서투른 테스트를 건너 뛸 수 있습니다.
#initialization as before
let lastyear=currentyear-1
for year in $(seq $year $lastyear); do
#do stuff with $year
done
#now months of the current year
for month in $(seq $incmonth $crntmnth); do
#do stuff with $month and $currentyear
done
어쨌든 이중 루프는 쓸모가 없었습니다. 올해는 한 번만 발생합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다