Reusability
Write one function and reuse it with different values.
Shell Script · Function Arguments
Shell Scripting · Lesson 15
Pass arguments to shell functions. Access parameters inside function. Build dynamic reusable code. Real automation examples.
Function arguments allow you to pass values into a function when calling it. These values can then be used inside the function using positional parameters.
Write one function and reuse it with different values.
Change behavior without changing code.
Pass runtime values into functions.
$1 – First argument$2 – Second argument$# – Total number of arguments$@ – All arguments (as list)$* – All arguments as a single stringArguments passed to a function are accessed using $1, $2, etc.
You can pass multiple arguments to a function.
Special variables like $#, $@, and $* provide argument info.
Shift moves positional parameters to the left.
Next lesson: Script Arguments ($0, $1, $@)