Bash foreach 스타일

Jmnote (토론 | 기여)님의 2021년 9월 15일 (수) 15:38 판 (→‎개요)

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
# [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
ARR=("John Smith" "Jane Doe" "Mike Barnes" "Kevin Patterson")
for i in "${!ARR[@]}"; do
	echo [$((i+1))/${#ARR[@]}] ${ARR[$i]}
done
# [1/4] John Smith
# [2/4] Jane Doe
# [3/4] Mike Barnes
# [4/4] Kevin Patterson

2 같이 보기

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