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?

  • 2
    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
    Commented Jan 30, 2013 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? Commented Jan 30, 2013 at 22:32
  • Did that; it isn't what I'm after. Commented Jan 30, 2013 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
    Commented Jan 31, 2013 at 7:12

2 Answers 2


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

  • +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
    Commented Jan 31, 2013 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .