0
0
Bash Scriptingscripting~15 mins

Calling functions in Bash Scripting - Mini Project: Build & Apply

Choose your learning style9 modes available
Calling functions
📖 Scenario: You are writing a simple bash script to organize tasks into functions. Functions help you reuse code and keep your script clean.
🎯 Goal: Create a bash script with a function that prints a greeting message. Then call that function to show the message.
📋 What You'll Learn
Create a function named greet that prints the text Hello, welcome to bash scripting!
Call the function greet after its definition
💡 Why This Matters
🌍 Real World
Functions in bash scripts help organize tasks like backups, monitoring, or automation steps. Calling functions makes scripts easier to read and reuse.
💼 Career
Knowing how to write and call functions in bash is essential for system administrators, DevOps engineers, and anyone automating tasks on Linux or Unix systems.
Progress0 / 4 steps
1
Create the greet function
Write a bash function named greet that prints the exact text Hello, welcome to bash scripting! using echo. Use the syntax: greet() { ... }
Bash Scripting
Need a hint?

Use echo inside the function to print the message.

2
Call the greet function
After the greet function definition, write a line to call the function by its name greet.
Bash Scripting
Need a hint?

Just write the function name greet on a new line to call it.

3
Add a comment explaining the function call
Add a comment line before the function call that says # Call the greet function.
Bash Scripting
Need a hint?

Comments start with # in bash scripts.

4
Run the script and show the output
Run the script and print the output. The output should be exactly Hello, welcome to bash scripting!
Bash Scripting
Need a hint?

Run the script in your terminal using bash scriptname.sh or ./scriptname.sh if executable.