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

2번째 줄: 2번째 줄:
;Bash foreach 스타일
;Bash foreach 스타일


<source lang='bash'>
ARR=(bash c python)
for VALUE in "${ARR[@]}"; do
echo "[$VALUE]"
done
# [bash]
# [c]
# [python]
</source>
<source lang='bash'>
<source lang='bash'>
ARR=("John Smith" "Jane Doe" "Mike Barnes" "Kevin Patterson")
ARR=("John Smith" "Jane Doe" "Mike Barnes" "Kevin Patterson")

2020년 1월 23일 (목) 20:00 판

1 개요

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

2 같이 보기

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