Challenge - 5 Problems
Function Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of a simple function call
What is the output of this Bash script?
Bash Scripting
greet() {
echo "Hello, $1!"
}
greet WorldAttempts:
2 left
💡 Hint
Look at how the function uses the first argument.
✗ Incorrect
The function greet prints 'Hello, ' followed by the first argument passed to it, which is 'World'.
💻 Command Output
intermediate2:00remaining
Function with local variable scope
What will be the output of this script?
Bash Scripting
count=5 myfunc() { local count=10 echo $count } myfunc echo $count
Attempts:
2 left
💡 Hint
Remember local variables inside functions do not change outside variables.
✗ Incorrect
Inside the function, count is local and set to 10. Outside, count remains 5. So the outputs are 10 then 5.
📝 Syntax
advanced2:00remaining
Identify the syntax error in function definition
Which option contains a syntax error in defining a Bash function?
Attempts:
2 left
💡 Hint
Check if the function body is properly enclosed.
✗ Incorrect
Option B misses curly braces around the function body, causing a syntax error.
🔧 Debug
advanced2:00remaining
Why does this function not print the argument?
Given this script, why does it print nothing?
myfunc() {
echo $name
}
myfunc John
Attempts:
2 left
💡 Hint
How do functions access passed arguments in Bash?
✗ Incorrect
In Bash, function arguments are accessed with $1, $2, etc. The variable $name is empty here.
🚀 Application
expert2:00remaining
Function calling another function with output capture
What is the output of this script?
Bash Scripting
get_date() {
date +"%Y-%m-%d"
}
print_message() {
local today=$(get_date)
echo "Today is $today"
}
print_messageAttempts:
2 left
💡 Hint
The inner function output is captured with $(...).
✗ Incorrect
The function get_date returns the current date in YYYY-MM-DD format. print_message captures it and prints it.