3

What does declare +x do below? (Specific to Bash.) I understand declare -x, but not declare +x:

function the_func { declare +x MY_VAR="new value" child-process } export MY_VAR="original" the_func 
1
  • 1
    Take a look at command: help declare Commented Mar 28, 2016 at 7:43

1 Answer 1

2

With

declare -x MY_VAR="new value" 

you export variable MY_VAR into the environment, whereas with

declare +x MY_VAR="new value" 

you remove that variable from the environment.

Generally speaking, for the declare command, using + undoes the action done by -.

More info can be found here

Sign up to request clarification or add additional context in comments.

1 Comment

declare -x is not same as export, if you call it inside fuction declare -x will export it only within scope of function, where export do export into environment OS

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.