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

  • 2
    what's wrong with echo $COMP_WORDS? – Zanna May 20 '17 at 15:45
  • It is perfect. I don't thought in that posibility – Emilio Platzer May 20 '17 at 15:47

To get the value of VARIABLE you can use


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

| improve this answer | |

You can use printenv:

$ export var=foo
$ printenv var

In alternative to echo you can also use printf.

printf "%s\n" $COMP_WORDS
| improve this answer | |
  • 1
    With printf you should do printf "%s\n" "$COMP_WORDS", so that the variable's contents are not interpreted as a format string. – muru May 20 '17 at 17:56

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
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.