Initiate this type of variables in the following ways:
variable_name="value"
and we use them, a forward their value a dollar sign ($).
echo $variable_name
Note:
Note that the sign between the variable name is equal to the value of the variable and there are no spaces or other whitespace characters - this is a mistake. This is a figment bash, in other languages do not have (this is a mistake often committed by novice programmers).
Example:
x ="string"
echo $x
echo $x
Under the variable we substitute the result of a command, you can do this in two ways:
1. By using reverse quotes:
variable=`command`
Example:
#!/bin/bash
WHERE_AM_I = `pwd`
WHO_AM_I = `whoami`
echo "My name is $WHO_AM_I and I live in $WHERE_AM_I"
WHERE_AM_I = `pwd`
WHO_AM_I = `whoami`
echo "My name is $WHO_AM_I and I live in $WHERE_AM_I"
The value of the variable WHO_AM_I, WHERE_AM_I is the result of the command whoami and pwd, respectively, which list the name of the user (whoami) and the directory in which they currently find (pwd).
2. With the development of the contents of the parentheses:
$(command)
Example:
#!/bin/bash
WHERE_AM_I =$ (pwd)
echo "I am in $WHERE_AM_I"
WHERE_AM_I =$ (pwd)
echo "I am in $WHERE_AM_I"