From the course: Learning Linux Shell Scripting

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Using parameters

Using parameters - Linux Tutorial

From the course: Learning Linux Shell Scripting

Start my 1-month free trial

Using parameters

- [Instructor] We can pass parameters to our functions similar to the way we pass them to our scripts by using the parameter symbols. Let's modify our func script to pass a name to the hello and goodbye functions. We pass parameters by following the function name with the parameter's value. So, in this case we're gonna say hello and we're gonna give it a name and we'll say Bob and for goodbye we'll give it a name also and call it Robert. Inside the function we can access the parameters by their symbols, $1 is the first parameter, $2 is the second and so forth. We could assign the parameters to global variables if we like or we could use a local variable. Let's use a local variable. So, we'll say local LNAME equals $1. And then here in the string we'll say hello $LNAME. So, LNAME is our local name. We don't necessarily have to use a local name but that just makes it so that LNAME is not defined outside of the hello function. And we'll take it easy inside of the goodbye function and…

Contents