0
0
Bash Scriptingscripting~15 mins

Accessing variables ($var and ${var}) in Bash Scripting - Mini Project: Build & Apply

Choose your learning style9 modes available
Accessing variables ($var and ${var}) in Bash scripting
📖 Scenario: You are writing a simple bash script to greet users and show their favorite fruit. You want to learn how to use variables correctly in bash scripts.
🎯 Goal: Build a bash script that stores a user's name and favorite fruit in variables, then prints a greeting using both $var and ${var} syntax.
📋 What You'll Learn
Create variables with exact names and values
Use both $var and ${var} syntax to access variables
Print the greeting message exactly as instructed
💡 Why This Matters
🌍 Real World
Using variables is essential in bash scripts to store and reuse information like user input, file names, or configuration values.
💼 Career
Knowing how to access variables correctly is a fundamental skill for system administrators, DevOps engineers, and anyone automating tasks with shell scripts.
Progress0 / 4 steps
1
Create variables for name and fruit
Create a variable called name and set it to "Alice". Create another variable called fruit and set it to "apple".
Bash Scripting
Need a hint?

Use name="Alice" and fruit="apple" to create the variables.

2
Create a greeting message using $var syntax
Create a variable called greeting1 and set it to the string Hello, $name! Your favorite fruit is $fruit. using the $var syntax to access the variables.
Bash Scripting
Need a hint?

Use double quotes and $name, $fruit inside the string.

3
Create a greeting message using ${var} syntax
Create a variable called greeting2 and set it to the string Hello, ${name}! Your favorite fruit is ${fruit}. using the ${var} syntax to access the variables.
Bash Scripting
Need a hint?

Use double quotes and ${name}, ${fruit} inside the string.

4
Print both greeting messages
Print the variables greeting1 and greeting2 each on its own line using echo.
Bash Scripting
Need a hint?

Use echo "$greeting1" and echo "$greeting2" to print the messages.