0
0
Bash Scriptingscripting~15 mins

Running commands in background (&) in Bash Scripting - Mini Project: Build & Apply

Choose your learning style9 modes available
Running Commands in Background with & in Bash
📖 Scenario: You are managing a server where you need to run multiple tasks without waiting for each to finish before starting the next. Running commands in the background helps you do this efficiently.
🎯 Goal: Learn how to run commands in the background using & so you can start a task and continue working without waiting for it to finish.
📋 What You'll Learn
Create a simple command that runs in the foreground
Add a background command using &
Use a variable to hold a command string
Run the command stored in the variable in the background
Print a message after starting the background command
💡 Why This Matters
🌍 Real World
Running commands in the background is useful when you want to start long tasks but keep using the terminal for other work.
💼 Career
System administrators and developers often run scripts and commands in the background to improve productivity and manage multiple tasks efficiently.
Progress0 / 4 steps
1
Create a simple command
Write a command that uses echo to display the text "Starting task".
Bash Scripting
Need a hint?

Use echo "Starting task" to print the message.

2
Run a command in the background
Add a command that runs sleep 5 in the background using & so it does not block the terminal.
Bash Scripting
Need a hint?

Add & after sleep 5 to run it in the background.

3
Use a variable to hold a command
Create a variable called cmd and assign it the string "sleep 3". Then run the command stored in cmd in the background using &.
Bash Scripting
Need a hint?

Assign cmd="sleep 3" and run it with $cmd &.

4
Print a message after starting background commands
Add a command to print "Tasks started" after starting the background commands.
Bash Scripting
Need a hint?

Use echo "Tasks started" to print the message.