How do I use variables with echo?

QuestionsQuestions4 SkillsProYour First Linux LabDec, 09 2025
090

You can use variables with the echo command in Linux by referencing the variable with a dollar sign ($). Here’s how to do it:

Steps:

  1. Declare a Variable:

    my_variable="Hello LabEx"
    
  2. Use echo to Display the Variable:

    echo $my_variable
    

Example:

my_variable="Hello LabEx"
echo $my_variable

Output:

Hello LabEx

Notes:

  • If the variable name is followed by characters that could be part of a variable name, enclose it in curly braces:
    echo ${my_variable}World  # Outputs: Hello LabExWorld
    

Using variables with echo is a great way to display dynamic content in your scripts. If you have more questions or need further examples, let me know!

0 Comments

no data
Be the first to share your comment!