Using Function Arguments ($1, $2 inside function) in Bash
📖 Scenario: You are writing a small bash script to greet users by their first and last names. You want to practice how to pass arguments to a function and use $1 and $2 inside the function to access those arguments.
🎯 Goal: Build a bash script with a function called greet that takes two arguments: first name and last name. The function should print a greeting message using these arguments.
📋 What You'll Learn
Create a function named
greet that accepts two arguments.Use
$1 and $2 inside the function to access the first and second arguments.Call the function with the exact arguments
John and Doe.Print the greeting message:
Hello, John Doe!💡 Why This Matters
🌍 Real World
Passing arguments to functions is common in bash scripts to reuse code and handle dynamic input, such as user names or file names.
💼 Career
Understanding function arguments in bash is essential for automation tasks, system administration, and writing maintainable shell scripts.
Progress0 / 4 steps