Escaping variables inside other variables in bash scripts

Say you have a variable that comprises of another variable like so:

var_name=test
var_name_full=$var_name_and_extension

The above won’t work as bash will interpret the underscore after $var_name as part of the variable name and look for a variable called $var_name_and_extension and not find it.

Two ways to solve this:

Enclose in curly braces as follows:

var_name=test
var_name_full=${var_name}_and_extension

Use double quotes to delineate between the variable name and the string:

var_name=test
var_name_full=$var_name"_and_extension"