Why functions organize reusable code
📖 Scenario: You are working on a small script to greet users by name. Instead of writing the greeting code multiple times, you want to organize it using a function. This makes your script cleaner and lets you reuse the greeting easily.
🎯 Goal: Build a bash script that defines a function to greet a user by name, then calls this function with different names.
📋 What You'll Learn
Create a function named
greet that takes one argument (a name).Inside the function, print the message:
Hello, <name>! where <name> is the argument.Call the
greet function twice with the names Alice and Bob.Print the greetings exactly as specified.
💡 Why This Matters
🌍 Real World
Functions help automate repetitive tasks in scripts, like sending emails or processing files multiple times with different data.
💼 Career
Knowing how to write and use functions in scripts is essential for system administrators, DevOps engineers, and anyone automating workflows.
Progress0 / 4 steps