I have a Main shell that runs a profile, The profile contains some variables such as Count. When I call the main shell, it loads the profile and then call another shell script. I want that inner shell script be able to access the variable count that the main shell script loaded already. How can I do that ? I tried export but only helped in one level variable import.

share|improve this question
feedback

2 Answers

export allows variables defined in a process, to be read in sub process, but if variable is modified in sub process, the variable will not change in caller process, because each process has it's own environment variables. Maybe a solution can be the sub shell to write to output and caller shell to read ouput.

count=$(subprocess)
share|improve this answer
feedback

Don't call the inner scripts as separate processes, call them as included scripts.

. /path/to/inner_script

Scripts read through the . (dot) built-in (also available under the name source in bash) are executed in the same shell environment as the caller. In particular, they share variables.

share|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

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