On this article, we are going to discover methods to echo a variable in bash. We’ve applied all bash instructions on Ubuntu 20.04. We’ll focus on some examples via which you’ll be able to simply perceive the fundamental ideas.
Right here, is the fundamental syntax of methods to echo a variable is given under:
Within the above command echo is a command that’s used for displaying the worth of variable ‘var_name’. Var_name is the title of a variable.
Open the terminal by urgent ‘Ctrl + Alt + t’ or launch terminal from the applying search bar. To try this, click on on the ‘Actions’ situated on the left nook in Ubuntu 20.04 and the write ‘terminal’ within the search bar as follows:
Launch the terminal by clicking on the terminal icon.
Echo Single Variable
Utilizing the echo command you possibly can echo the worth of a variable. Simply you could declare and assign worth to a variable after which merely echo the worth of the variable. On your good understanding, we are going to focus on some examples that are given under:
Instance # 01:
Let’s take an instance, we need to show the worth of a variable named ‘var_a’ that has a worth 100. Now, utilizing the echo command we will merely show its worth on the terminal as follows:
The next output you’ll on the terminal:
Instance # 02:
Let’s focus on one other instance, we need to show the textual content ‘bash programming echo variable’ on the terminal through the use of the variable. So, take a variable named ‘var_b’ and retailer the above textual content on this variable with double-quotes.
$ var_b=” bash programming echo variable”
$ echo $var_b
You will note the next output on the terminal:
Notice: if you’ll use echo var_b then it can solely show the variable title on the terminal as an alternative of displaying its worth.
Echo A number of Variables
The next instance will present you methods to echo multiples variables:
Instance # 01:
For instance, take two variables var_A and var_B.
$ echo $var_A$var_B
The next output will show on the terminal:
Instance # 02:
For instance, we need to show the date and hostname of our pc. So, we are going to retailer the date and hostname instructions in var1 and var2 respectively. You may see the implementation as follows:
$ echo “the date is $var1 @ pc title is $var2”
After working the above command, you will notice the next output:
On this article, we’ve proven methods to show a variable worth or textual content output through the use of the echo command. We’ve executed completely different bash variables examples on the terminal for higher understanding. From the above instructions, I hope now you’re conversant in methods to echo variables and textual content in bash programming. Moreover, you should use completely different instructions to retailer contained in the variable. Please, let me know in case of any drawback associated to this text.
bash echo asterisk,yes please command in linux,bash echo "-ne",bash echo special characters,bash echo command output,bash echo to file,bash internal variables,declare script,bash declare,bash,bash pid of last command,bash variables $0,assign echo output to variable bash,how to echo double quotes in bash,echo command in linux,shell script echo variable,linux echo -e,display message in linux,echo user will result in what output in linux,echo command output bash