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

잔글 (Jmnote님이 Bash foreach 문서를 Bash foreach 스타일 문서로 이동했습니다)
38번째 줄: 38번째 줄:


[[분류: Bash]]
[[분류: Bash]]
[[분류: foreach]]

2020년 1월 23일 (목) 19:55 판

1 개요

Bash foreach 스타일
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 }}