From the course: Linux Bash Shells and Scripts: Streamlining Tasks and Enhancing Workflows with Automation

Unlock this course with a free trial

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

Shell parameter expansion

Shell parameter expansion

- [Instructor] Let's look at another kind of more advanced, but valuable, can save you a lot of programming, mechanism in bash that works with variables and values. Now, maybe you don't want to use this because it's a little bit of a challenge to get the hang of it in the beginning perhaps, but if you ever see this in someone's shell script, you want to know kind of what's going on so you can get a grasp or maybe at least look up what's going on and have it make more sense. So what happens here is you can use an operator inside this dollar sign brace stuff. For example, the colon dash is used to check whether a variable is unset or null. And if it's not, then you get the value of the variable. But it it is unset or null, then you get the value on the right-hand side. So it's kind of like getting a default value for a variable. If you do the colon equal, then if the variable doesn't currently have a value, then it's assigned that value and it's also returned. So these are handy ways of…

Contents