Learn
Learn Bash Scripting
Variables

Within bash scripts (or the terminal for that matter), variables are declared by setting the variable name equal to another value. For example, to set the variable greeting to “Hello”, you would use the following syntax:

greeting="Hello"

Note that there is no space between the variable name, the equals sign, or “Hello”.

To access the value of a variable, we use the variable name prepended with a dollar sign ($). In the previous example, if we want to print the variable value to the screen, we use the following syntax:

echo $greeting

Instructions

1.

Create a variable phrase on the line before the current echo statement. Set the phrase equal to the string “Hello to you!”.

2.

Update the echo statement to make use of the variable instead of the fixed string.

3.

Run the script in the terminal.

Folder Icon

Sign up to start coding

Already have an account?