0
0
Bash Scriptingscripting~10 mins

Variable assignment (no spaces around =) in Bash Scripting - Mini Project: Build & Apply

Choose your learning style9 modes available
Variable assignment (no spaces around =)
📖 Scenario: You are writing a simple bash script to store and display your favorite fruit.
🎯 Goal: Create a variable to hold the name of your favorite fruit and then print it.
📋 What You'll Learn
Create a variable called fruit with the value Apple using no spaces around the = sign.
Create a variable called count with the value 3 using no spaces around the = sign.
Use a variable called total to store the sum of count and 2.
Print the value of fruit and total.
💡 Why This Matters
🌍 Real World
Bash scripts often use variables to store data like file names, counts, or user input. Correct variable assignment is essential for scripts to work.
💼 Career
Many IT and DevOps jobs require writing bash scripts for automation. Knowing how to assign and use variables correctly is a basic but crucial skill.
Progress0 / 4 steps
1
Create the fruit variable
Create a variable called fruit and assign it the value Apple with no spaces around the = sign.
Bash Scripting
Need a hint?

Remember, in bash, do not put spaces around the = sign when assigning variables.

2
Create the count variable
Create a variable called count and assign it the value 3 with no spaces around the = sign.
Bash Scripting
Need a hint?

Use the same style as the fruit variable assignment.

3
Calculate the total variable
Create a variable called total that stores the sum of count and 2. Use $(( )) for arithmetic and no spaces around the = sign.
Bash Scripting
Need a hint?

Use total=$((count + 2)) to do arithmetic in bash.

4
Print the variables
Print the value of fruit and total using echo. Use $fruit and $total to access the variables.
Bash Scripting
Need a hint?

Use echo $fruit and echo $total to print the values.