"Bash foreach 스타일"의 두 판 사이의 차이

태그: 수동 되돌리기
 
(같은 사용자의 중간 판 8개는 보이지 않습니다)
2번째 줄: 2번째 줄:
;Bash foreach 스타일
;Bash foreach 스타일


<source lang='bash'>
<syntaxhighlight lang='bash' run>
ARR=(bash c python)
ARR=(bash c python)
for VALUE in "${ARR[@]}"; do
for VALUE in "${ARR[@]}"; do
echo "[$VALUE]"
echo "[$VALUE]"
done
done
# [bash]
</syntaxhighlight>
# [c]
<syntaxhighlight lang='bash' run>
# [python]
</source>
<source lang='bash'>
ARR=("John Smith" "Jane Doe" "Mike Barnes" "Kevin Patterson")
ARR=("John Smith" "Jane Doe" "Mike Barnes" "Kevin Patterson")
for VALUE in "${ARR[@]}"; do
for VALUE in "${ARR[@]}"; do
echo "[$VALUE]"
echo "[$VALUE]"
done
done
# [Jonh Smith]
</syntaxhighlight>
# [Jane Doe]
<syntaxhighlight lang='bash' run>
# [Mike Barnes]
# [Kevin Patterson]
</source>
<source lang='bash'>
ARR=("John Smith" "Jane Doe" "Mike Barnes" "Kevin Patterson")
ARR=("John Smith" "Jane Doe" "Mike Barnes" "Kevin Patterson")
for i in "${!ARR[@]}"; do
for i in "${!ARR[@]}"; do
echo $i: ${ARR[$i]}
echo $i: ${ARR[$i]}
done
done
# 0: John Smith
</syntaxhighlight>
# 1: Jane Doe
<syntaxhighlight lang='bash' run>
# 2: Mike Barnes
# 3: Kevin Patterson
</source>
<source lang='bash'>
ARR=("John Smith" "Jane Doe" "Mike Barnes" "Kevin Patterson")
ARR=("John Smith" "Jane Doe" "Mike Barnes" "Kevin Patterson")
for i in "${!ARR[@]}"; do
for i in "${!ARR[@]}"; do
echo $((i+1)): ${ARR[$i]}
echo $((i+1)): ${ARR[$i]}
done
done
# 1: John Smith
</syntaxhighlight>
# 2: Jane Doe
<syntaxhighlight lang='bash' run>
# 3: Mike Barnes
ARR=("John Smith" "Jane Doe" "Mike Barnes" "Kevin Patterson")
# 4: Kevin Patterson
for i in "${!ARR[@]}"; do
</source>
echo [$((i+1))/${#ARR[@]}] ${ARR[$i]}
done
</syntaxhighlight>


==같이 보기==
==같이 보기==
* [[Bash 배열]]
* [[Bash for]]
* [[Bash for]]
* [[foreach]]
* [[foreach]]

2022년 2월 3일 (목) 12:00 기준 최신판

1 개요[ | ]

Bash foreach 스타일
ARR=(bash c python)
for VALUE in "${ARR[@]}"; do
	echo "[$VALUE]"
done
ARR=("John Smith" "Jane Doe" "Mike Barnes" "Kevin Patterson")
for VALUE in "${ARR[@]}"; do
	echo "[$VALUE]"
done
ARR=("John Smith" "Jane Doe" "Mike Barnes" "Kevin Patterson")
for i in "${!ARR[@]}"; do
	echo $i: ${ARR[$i]}
done
ARR=("John Smith" "Jane Doe" "Mike Barnes" "Kevin Patterson")
for i in "${!ARR[@]}"; do
	echo $((i+1)): ${ARR[$i]}
done
ARR=("John Smith" "Jane Doe" "Mike Barnes" "Kevin Patterson")
for i in "${!ARR[@]}"; do
	echo [$((i+1))/${#ARR[@]}] ${ARR[$i]}
done

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}