6

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
10

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

| improve this answer | |
7

You can use printenv:

$ export var=foo
$ printenv var
foo

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
4

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\"
'"
| 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.