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.
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.
Don't call the inner scripts as separate processes, call them as included scripts.
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.