From the course: Learning Linux Shell Scripting

Unlock the full course today

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

Creating and using variables

Creating and using variables - Linux Tutorial

From the course: Learning Linux Shell Scripting

Start my 1-month free trial

Creating and using variables

- Simply echoing text directly to the screen is bound to get boring. In order to start making dynamic scripts, we need to understand how to create and use variables. Let's return to the terminal, we're gonna type touch, greeting, dot sh, we're gonna do change mode, seven, five, five. On greeting, dot, sh. And finally we're going to open up the atom editor. Alright we're gonna add our shebang. And then we'll add a couple of variables. So we're gonna go first name equals Bob and favorite color equals blue. And we'll type echo, HI. And if you want to display the contents of a variable you need to proceed it with a dollar sign. So dollar sign. First name, comma, your favorite color is and then dollar sign, favorite color. And then we're gonna save this with a control S, return to the terminal and we're gonna just say dots, forward slash, greeting dot, sh. We get, Hi Bob, your favorite color is blue. A variable is created by putting a equal sign between a name on the left side and a value…

Contents