$
학습 Linux 안내서
ko
XP:0
퀘스트 106Loop-Master
+260 XP

while Loops & case Statements

이 퀘스트를 위한 인터랙티브 터미널 시작→설치 불필요 • 브라우저에서 바로 실행

개념 및 개요

Two of the most common control structures in systems engineering scripts are file-reading loops and case branches:

1. File-reading while loop: Reads input line by line safely using read -r without interpreting escape characters:
while read -r line; do echo "Processing: $line"; done < names.txt

2. case statement: Matches a variable against multiple patterns cleaner than multiple if/elif blocks:
case $1 in start) systemctl start app ;; stop) systemctl stop app ;; *) echo "Usage: $0 {start|stop}" ;; esac

Process entries in names.txt line by line by running: while read -r line; do echo "User: $line"; done < names.txt. Then test a case conditional dispatch: case "start" in start) echo "Service starting" ;; stop) echo "Service stopping" ;; esac.

명령어 구문 참조

Command / SyntaxDescription
while read -r line; do echo "User: $line"; done < names.txtIterate over lines in a file
case "start" in start) echo "Service starting" ;; esacExecute pattern match case block

검증 목표

  • ○
    Execute while read loop iterating over names.txt
  • ○
    Execute case pattern matching statement

퀘스트를 완료할 준비가 되셨나요? 106?