You can use the echo command with variables in Linux by referencing the variable name with a dollar sign ($). Here’s how you can do it:
-
Define a variable:
my_variable="Hello, World!" -
Use
echoto display the variable:echo $my_variable
This will output:
Hello, World!
Example with Multiple Variables
You can also use multiple variables in a single echo command:
greeting="Hello"
name="Alice"
echo "$greeting, $name!"
This will output:
Hello, Alice!
Important Note
- Always enclose variables in double quotes (
") when using them inechoto preserve spaces and special characters.
