0
0
Bash Scriptingscripting~20 mins

Why variables store and reuse data in Bash Scripting - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Variable Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Bash script?
Consider this Bash script that uses a variable to store a value and reuse it later. What will it print?
Bash Scripting
name="Alice"
echo "Hello, $name!"
name="Bob"
echo "Hello again, $name!"
AHello, Alice!\nHello again, Bob!
BHello, Alice!\nHello again, Alice!
CHello, Bob!\nHello again, Bob!
DHello, Bob!\nHello again, Alice!
Attempts:
2 left
💡 Hint
Variables hold the value assigned at the time of use.
🧠 Conceptual
intermediate
1:30remaining
Why do we use variables in scripts?
Which of these best explains why variables are used in scripting?
ATo make scripts run faster by skipping commands.
BTo store data temporarily so it can be reused and changed easily.
CTo permanently save data to the computer's hard drive.
DTo prevent the script from running more than once.
Attempts:
2 left
💡 Hint
Think about how you remember information to use it again.
🔧 Debug
advanced
2:00remaining
Why does this script print an empty line?
Look at this Bash script: ``` message=Hello message ``` Why does it print an empty line instead of 'Hello'?
ABecause the script needs 'echo' to print anything.
BBecause variables cannot store strings without quotes.
CBecause 'message' is not called with a $ sign to access its value.
DBecause the variable was not declared with 'declare'.
Attempts:
2 left
💡 Hint
Think about how to print text in Bash.
📝 Syntax
advanced
1:30remaining
Which option correctly assigns and reuses a variable in Bash?
Choose the correct Bash code that assigns '5' to a variable and then prints it.
A
num = 5
echo $num
B
num=5
echo $num()
C
num=5
echo $num
D
num=5
echo num
Attempts:
2 left
💡 Hint
Remember, no spaces around '=' and use $ to access variable value.
🚀 Application
expert
2:30remaining
What is the value of 'result' after running this script?
Given this Bash script: ``` count=3 result=$((count * 2)) count=5 result=$((result + count)) echo $result ``` What number will be printed?
A8
B6
C16
D11
Attempts:
2 left
💡 Hint
Follow the math step by step, updating variables as you go.