-2

This question already has an answer here:

How to refer variable defined in sub shell in parent shell. command grouping is difficult in my case. What would be the alternative.

marked as duplicate by Gilles shell Jan 17 '17 at 23:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 4
    XY problem. What are you actually trying to do? – muru Jan 17 '17 at 6:37
  • Please update the question with the relevant code and a description of what it is you're trying to achieve. – Kusalananda Jan 17 '17 at 8:14
  • 1
    You have a few options. If it's an integer, you can return it as the subshell status. You can have the subshell print to stdout and capture into a variable. You can use a temporary file. It'd be better if you stated what you are trying to do instead of how you are trying to do. – giusti Jan 17 '17 at 10:23
  • I have some set of variables in parent shell and when i call my child script it will change those values and these variables store non-numeric. After calling child script, based on modified values of my variables, i need to write some code in parent script. – NaviKesh Doddi Jan 18 '17 at 11:23
5

You can't.

If you have defined a variable in a subshell (and export that), it won't be propagated to the parent's environment. This is by design.

You can only pass them downwards, meaning to only the child's environment.

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