Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
you mean to use these variables as globals that can be changed by any sub shell, and have that change be recognized by all sub shells including the main shell so all shells will read the value updated by that child shell and be able to work on the updated value? – Aquarius Power Sep 17 '13 at 23:24

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.

share|improve this answer

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

Your Answer


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.