"쉘 프로그래밍 제어문"의 두 판 사이의 차이

5번째 줄: 5번째 줄:
==조건문==
==조건문==
===if===
===if===
<source lang='bash'>
He="John Smith"
if [ "$He" = "John Smith" ]; then
echo "He is John Smith"
else
echo "He is not John Smith"
fi
# He is John Smith
</source>
<source lang='bash'>
He="Jane Doe"
if [ "$He" != "John Smith" ]; then
echo "He is not John Smith"
fi
# He is not John Smith
</source>


==반복문==
==반복문==

2018년 12월 10일 (월) 00:26 판

1 개념

Shell Programming / Control Statement; Flow Control Statement
쉘 프로그래밍 / 제어문

2 조건문

2.1 if

He="John Smith"
if [ "$He" = "John Smith" ]; then
	echo "He is John Smith"
else
	echo "He is not John Smith"
fi
# He is John Smith
He="Jane Doe"
if [ "$He" != "John Smith" ]; then
	echo "He is not John Smith"
fi
# He is not John Smith

3 반복문

3.1 for

  • 문법
for i [in LIST]
do
    // Do something
done
→LIST는 반복이 가능한 숫자, 문자열 등이 들어감
  • for문 예시
#!/bin/bash
LIST=$(ls)

for i in $LIST
do
    echo $i
done
→LIST에 현재 디렉토리에서 ls명령 수행 결과값들이 들어감
→for문에서 LIST변수 값들이 출력됨
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}