$
학습 Linux 안내서
ko
XP:0
퀘스트 105Script-Automator
+260 XP

User Input & Command Substitution (read & $(...))

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

개념 및 개요

Interactive and automated scripts rely on two essential shell capabilities:

1. User Input (read): Prompts the user to enter data and stores the response in a shell variable. The -p flag prints a custom prompt string:
read -p "Enter username: " USERNAME

2. Command Substitution ($(...)): Executes a command in a subshell and substitutes its standard output into the variable or command line:
TODAY=$(date +%F)

This lets you create dynamic timestamped filenames and automated reports.

Prompt for a username variable using read -p "Enter username: " USERNAME. Then capture today's formatted date into a variable with TODAY=$(date +%F). Finally, display the captured date with echo $TODAY.

명령어 구문 참조

Command / SyntaxDescription
read -p "Enter username: " USERNAMEPrompt user for input and save in variable
TODAY=$(date +%F)Store command output in variable
echo $TODAYDisplay value of variable

검증 목표

  • ○
    Prompt for input using "read -p"
  • ○
    Capture date with "TODAY=$(date +%F)"
  • ○
    Display variable with "echo $TODAY"

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