쉘 프로그래밍 제어문

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변수 값들이 출력됨

4 같이 보기[ | ]

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