Ubuntu: How to get the value of an exported variable in the console


If I wrote

export COMP_WORDS="this words"  

I need something like

get-exported COMP_WORDS  

expecting something like

COMP_WORDS="this words"  

I tried

set | grep COMP_WORDS  

but it takes others lines


To get the value of VARIABLE you can use

echo $VARIABLE  

The quotes don't survive though

$ COMP_WORDS="you said what?"  $ echo $COMP_WORDS  you said what?  

Unless you quote them...

$ quote='"2b || !2b"'  $ echo $quote  "2b || !2b"  

It makes no difference whether you set the variable yourself or not


You can use printenv:

$ export var=foo  $ printenv var  foo  

In alternative to echo you can also use printf.

printf "%s\n" $COMP_WORDS  


In bash, if you want output that's reusable setting the variable again, you can try declare:

$ declare -p USER  declare -x USER="muru"  $ export foo='abc  > def  > hij"  > '"'"  $ declare -p foo  declare -x foo="abc  def  hij\"  '"  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »