Reading into Multiple Variables in Bash
📖 Scenario: You work in a small office where you receive daily reports as single lines of text. Each line contains a person's first name, last name, and age separated by spaces. You want to write a simple script to read these details into separate variables for easy use later.
🎯 Goal: Build a Bash script that reads a single line of input containing a first name, last name, and age, and stores each piece of information into its own variable.
📋 What You'll Learn
Create a variable to hold the input line.
Create three variables:
first_name, last_name, and age.Use the
read command to split the input line into these three variables.Print the variables to confirm the values were stored correctly.
💡 Why This Matters
🌍 Real World
This technique helps when processing lines of text data, such as logs or reports, where each line contains multiple pieces of information separated by spaces.
💼 Career
Many automation and scripting tasks require parsing input into variables for further processing, making this a fundamental skill for system administrators and DevOps engineers.
Progress0 / 4 steps