Skip to main content

Command Palette

Search for a command to run...

Variables in Bash

Updated
•1 min read•View as Markdown
Variables in Bash

To create a variable in bash, you can just assign value to the variable using (=) equal to. There shouldn't be any spaces before or after = .

You can read the value inside variable by prefixing it with $ sign, the bash automatically replace $variable with it's value.

name=Loki
echo Welcome $name

Variable names are case-sensitive, meaning the variables result and Result are two different variables.

Using Quotes

use double quotes for substitution. If we use single quotes, it won't read the values in variables.

name=Loki
echo "Welcome $name"
# Welcome Loki
echo 'Welcome $name'
# Welcome $name