How to use echo with variables?

QuestionsQuestions8 SkillsProYour First Linux LabAug, 21 2025
0253

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:

  1. Define a variable:

    my_variable="Hello, World!"
  2. Use echo to 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 in echo to preserve spaces and special characters.

0 Comments

no data
Be the first to share your comment!