Overview
This guide covers core practical use cases for the read command, which is essential for handling interactive user input and parsing text data in Linux Bash shell scripts. You will master everything from basic input handling to password masking (-s), timeout handling (-t), delimiter splitting (IFS), and the widely used line-by-line file processing pattern based on while loops.
1. Basics of the read Command, Prompt (-p), and Setting Default Values
Run the mkdir -p ~/read-demo && cd ~/read-demo command to create and navigate to a dedicated directory for practicing the read command.

The read command reads a single line from standard input and stores it in a variable. You can specify a prompt string with the -p option and assign a fallback default value when input is empty using the ${variable:-default} syntax.
In the execution result, because no input was directly passed to the read command, the username variable remained empty, resulting in the default value guest being printed according to ${username:-guest}.
⚙️ [Key Options]
-p : Specifies a prompt message to display on the screen before receiving input.-s : Enables silent mode, which suppresses input characters from being displayed on the screen when accepting sensitive information such as passwords.-t : Sets a timeout limit (in seconds) for waiting for input; terminates input handling if the timeout expires.-n : Reads only the specified number of characters and terminates immediately without requiring the user to press Enter.-r : Disables backslash (\) escape interpretation, reading input raw as-is.-a : Splits words based on whitespace and stores them sequentially into an array variable.-d : Specifies a custom delimiter character to terminate input instead of a newline.

2. Password Masking (-s) and Input Timeout (-t) Handling
Run the cd ~/read-demo command to navigate to the previously created ~/read-demo directory and continue the practice.

Input is received while masking the screen with the -s option and enforcing a 5-second timeout with the -t 5 option.
Since the password was passed successfully within the timeout limit, the exit status code ($?) returned 0.

3. Splitting into Multiple Variables and Arrays Using Delimiters (IFS) and the -a Option
Run the cd ~/read-demo command to navigate to the previously created ~/read-demo directory and continue the practice.

After setting the Internal Field Separator (IFS) to a comma (,), the read command reads a CSV-formatted string passed via a Here-String (<<<) and splits it into col1, col2, and col3 variables.
As seen in the execution result, the server name, IP address, and service name included in the string were properly split and assigned to each variable according to the specified delimiter.

By setting the delimiter (IFS) to a colon (:) and using the -a option, a string formatted like /etc/passwd is split and stored into the user_info array variable.
The username (root) at index 0 and the login shell path (/bin/bash) at index 6 of the array were successfully extracted and printed.
![bash -c ‘IFS=":" read -ra user_info «< “root:x:0:0:root:/root:/bin/bash”; echo “계정명: ${user_info[0]}, 셸: ${user_info[6]}”’](/ubuntu/20261007_143401_98/captures/s03_c03_bash_-c__IFS_____read_-ra_user_info______root_x_0.png)
4. Practical Core: Line-by-Line Large File Processing Using while Loops and read -r
Run the cd ~/read-demo command to navigate to the previously created ~/read-demo directory and continue the practice.

Create servers.csv, a sample CSV file containing server names and operating statuses separated by commas, to practice line-by-line file processing.

By combining a while loop with read -r and setting the Internal Field Separator (IFS) to a comma (,), each line of the servers.csv file is safely read line by line.
In the output result, each server’s name and status recorded in the file were successfully split and assigned to the name and status variables, and then printed in the specified format.
![while IFS="," read -r name status; do echo “[상태 점검] $name 서버는 현재 $status 상태입니다.”; done < servers.csv](/ubuntu/20261007_143401_98/captures/s04_c03_while_IFS_____read_-r_name_status__do_echo___%EC%83%81%ED%83%9C_%EC%A0%90%EA%B2%80.png)
So far, we have covered the fundamentals of the read command in Linux shell scripts up to essential practical techniques for reading files line by line.
Try writing your own interactive automation scripts suited to your use cases using the various options and examples explored today.