How to display variables?

092

To display variables in the terminal, you can use the echo command. Here’s how you can do it:

  1. Define a variable:

    my_variable="Hello, World!"
  2. Display the variable using echo:

    echo $my_variable

This will output:

Hello, World!

Example with Multiple Variables

You can also display multiple variables at once:

name="Labby"
age=2
echo "My name is $name and I am $age years old."

This will output:

My name is Labby and I am 2 years old.

Using Curly Braces

For clarity, especially when concatenating variables with text, you can use curly braces:

echo "My name is ${name} and I am ${age} years old."

This will produce the same output as before.

0 Comments

no data
Be the first to share your comment!