From the course: Learning Linux Shell Scripting

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Passing parameters

Passing parameters

- [Instructor] We can get input from users of our scripts via parameters. Your script always receives parameters, even if it doesn't use them. Bash passes them in via some special symbols. The first parameter, $0 is special in that it is the path and name of the executing script. Generally, we don't use parameters past $9s since the use of curly braces with parameters is only supported in newer versions of the Bash shell. Parameters make it possible to be interactive with the user. If for example we want it to echo the user's name, we could do this. I'm gonna create another script. So we're gonna say, touch params.sh. We're gonna do a change mode 755 params.sh. And finally, atom, params.sh. And what we'll do is first put our shebang, and it's going to be usr/bin/env bash. And then we'll just do an echo Hello $1, which is our first parameter. And we'll save that with a Ctrl + S, go back to the terminal, and do a ./params.sh. And we get nothing, because I didn't type a name, but if we…

Contents