-2

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

  • 4
    XY problem. What are you actually trying to do? – muru Jan 17 '17 at 06: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 08: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

1 Answers1

6

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.

heemayl
  • 56,300