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'm trying to find the original definition declaration of a variable.

What linux commands or actions will output environment variable's source definition file and all files that have changed that variable?

Is there a way to trace the bin bash command echo down to it's source in BASH?

How does echo work in bash? Where is echo getting the value for a variable?

share|improve this question
You ask a lot of different questions here. What specific echo variable are you concerned with? Do you want to look at the source code for echo? Want to have verbose output in BASH while interpreting? Then use set -x and set +x and set to list vars. – user13742 Jan 30 '13 at 22:29
I want to see the file name of the source definition of any variable. Is this possible? Or do I need to dig? – alrightgame Jan 30 '13 at 22:32
Did that; it isn't what I'm after. – alrightgame Jan 30 '13 at 22:54
Please, one question per question. There is no limit to how many questions you can ask -- ask a separate one for each question :-) – Chris Down Jan 31 '13 at 7:12

Bash doesn't keep track of what line of what file set a given variable, and it would be terribly inefficient if it did so. But you can debug bash scripts using the -x flag.

See: Debugging Bash scripts

share|improve this answer
+1 Environment variables are simply an array of char* pointers, each one containing a pointer to a string variable=value. There is no facility for auditing which process changed which value. You would need to implement your own kernel functions and probably recompile most of the user-space binaries as well to change that. – tripleee Jan 31 '13 at 9:22

As far as I know, a variable is a variable and contains no information on what defined it. A possible workaround is to search inside files with grep, from your home directory or / (this may take a while):

grep -r "VARIABLE" * 2> /dev/null

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.