How Do You Show the Value of a Variable in Linux?
Contents the Most Used Command to Displays the Environment Variables Is Printenv. If the Name of the Variable Is Passed as an Argument to the Command, Only the...
Contents
The most used command to displays the environment variables is printenv . If the name of the variable is passed as an argument to the command, only the value of that variable is displayed. If no argument is specified, printenv prints a list of all environment variables, one variable per line.
How do I get the value of a variable in bash?
Now, using the echo command we can simply display its value on the terminal as follows:
- $ var_a=100. $ echo $var_a.
- $ var_b=” bash programming echo variable” $ echo $var_b.
- $ var_A=”hellofriends” $ var_B=50. $ echo $var_A$var_B.
- $ var1=$(date) $ var2=$(hostname) $ echo “the date is $var1 @ computer name is $var2”
Must Read
How do you echo the value of a variable?
To display the value of a variable, either use echo or printf command as follows:
- echo $varName # not advisable unless you know what the variable contains.
- echo “$varName”
- printf “%sn” “$varName”