0
0
Bash Scriptingscripting~15 mins

Adding and removing elements in Bash Scripting - Mini Project: Build & Apply

Choose your learning style9 modes available
Adding and Removing Elements in Bash Arrays
📖 Scenario: You are managing a list of tasks in a simple bash script. You want to add new tasks and remove completed ones from your list.
🎯 Goal: Build a bash script that creates an initial array of tasks, adds a new task, removes a specific task, and then prints the final list of tasks.
📋 What You'll Learn
Create a bash array called tasks with three exact tasks
Add a new task to the tasks array
Remove a specific task from the tasks array
Print the final list of tasks, one per line
💡 Why This Matters
🌍 Real World
Managing lists of items like tasks, filenames, or user inputs in bash scripts is common for automation and system administration.
💼 Career
Knowing how to manipulate arrays in bash helps automate repetitive tasks and manage data efficiently in many IT and DevOps roles.
Progress0 / 4 steps
1
Create the initial tasks array
Create a bash array called tasks with these exact tasks: "Buy groceries", "Clean house", and "Pay bills".
Bash Scripting
Need a hint?

Use parentheses () to create an array and double quotes "" around each task.

2
Add a new task to the array
Add a new task "Call mom" to the tasks array using the correct bash syntax.
Bash Scripting
Need a hint?

Use tasks+=("Call mom") to add an element to the array.

3
Remove a task from the array
Remove the task "Clean house" from the tasks array by creating a new array called filtered_tasks that excludes it.
Bash Scripting
Need a hint?

Use a for loop to check each task and add only those not equal to "Clean house" to filtered_tasks.

4
Print the final list of tasks
Print each task in the filtered_tasks array on its own line using a for loop and echo.
Bash Scripting
Need a hint?

Use for task in "${filtered_tasks[@]}" and echo "$task" to print each task.