Finding WHERE an environment variable is defined.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Finding WHERE an environment variable is defined.
# 1  
Old 04-18-2011
Finding WHERE an environment variable is defined.

HI. I had an environment variable defined in my .bash_profile file and I deleted it. I opened a new terminal and looked inside .bash_profile and it's not there but when I type

Code:
printenv MYCONFIG

it reutrns what the value used to be in my .bash_profile still!! I did a grep for MYCONFIG and the only place it showed up was .bash_history, and I even tried deleting that! What is the command to not just print the environment variable but to print where it is coming from? Why is it still defined!? SmilieSmilieSmilie
# 2  
Old 04-18-2011
There isn't one, because a var is just a var and contains no information on what defined it.

Open a new, separate session to see this take effect. It might still be inheriting the value from your old session if you run the new one inside it.
# 3  
Old 04-18-2011
Quote:
Originally Posted by Corona688
There isn't one, because a var is just a var and contains no information on what defined it.

Open a new, separate session to see this take effect. It might still be inheriting the value from your old session if you run the new one inside it.
Do you mean reboot my computer? because I opened a new terminal and it was still there...but my bash_profile was devoid of it ?
# 4  
Old 04-18-2011
Quote:
Originally Posted by dissectcode
Do you mean reboot my computer?
No.
Quote:
Because I opened a new terminal and it was still there...but my bash_profile was devoid of it ?
How about ~/.bashrc, then, or /etc/profile, or /etc/bash/bashrc ?
# 5  
Old 04-18-2011
Quote:
Originally Posted by Corona688
No. How about ~/.bashrc, then, or /etc/profile, or /etc/bash/bashrc ?

MYCONFIG is not in any of those places. I had the same problem last week with another environment variable PROMPT_COMMAND where it was set to:

Code:
PROMPT_COMMAND="pwd"

and I was sick of looking at the working directory with every new line on the CL and it wouldn't go away until I explicitly said PROMPT_COMMAND="" !

please help
# 6  
Old 04-18-2011
Try logging out of your GUI, then logging back in. Remember how environment variables work -- you inherit copies from whatever created your process. Maybe you're inheriting a copy from your GUI itself.
# 7  
Old 04-18-2011
You could try:
Code:
grep -r "MYCONFIG" * 2> /dev/null

In your /home/username or for a more thorough search in / (although it may take a while!)

Last edited by AlphaLexman; 04-18-2011 at 09:13 PM.. Reason: added '2> /dev/null'
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How are environment variables defined in a Gnome terminal session?

Hello... and thanks in advance for any help anyone can offer me with my question! I'm hoping someone will have a little patience with me and walk me through this! I'm trying to understand a user login process on Centos 7 and I've gotten a bit confused trying to figure out when/how a Gnome... (4 Replies)
Discussion started by: bodisha
4 Replies

2. UNIX for Beginners Questions & Answers

Awk: use variable defined in begin

Hi there, I'm working with file more than 400K lines, 60 columns. Column count is going to be multiple of 12: 60, 12, 72 or so. NF/12 gives me on how many iterations I've to do to check certain value. For example: 7, 14th if only 24 columns in file. 7th, 14th and 21st if 36 columns in... (6 Replies)
Discussion started by: genome
6 Replies

3. Shell Programming and Scripting

How do I get variable defined in BASH subshell outside?

I'm a BASH shell user (relatively new) I need to get a variable calculated in a subshell, outside the subshell, when it completes. I can do it, by writing the variable into a file, and then reading the file again when outside the subshell. I've tried lots of things from exporting to environmental... (3 Replies)
Discussion started by: goreilly
3 Replies

4. Shell Programming and Scripting

Doing math using user defined input and system environment variables

Hi, I need some help to setup some environmental variables. for example...Get A -> userdefined/user input B -> a number. c -> system variable...for example $GETCONF PAGE_SIZE E = do some math using bc display a message "The value is E" setup the system/kernel paramter sysctl -p... (3 Replies)
Discussion started by: saravanapandi
3 Replies

5. Shell Programming and Scripting

Defined Variable from text file

Hi Guys, I have one text file ABC.txt...It have 3 lines List=/home/klk/dir/ABC.txt Leajnk123 KJUHIO1234 IJOKIJ7676 I want use as different variable of each line.Just like X=firstline Y=Secound Line Z=Third Line (4 Replies)
Discussion started by: asavaliya
4 Replies

6. SCO

Help finding where certain environment variables are set

i have two machines that should be identical but on one system there are some oracle environment (ORACLE_SID, ORACLE_HOME, etc...) variables that are not being set for the users. I am trying to find where those environment variables are being set on the system which is working properly. All... (5 Replies)
Discussion started by: kuliksco
5 Replies

7. Shell Programming and Scripting

Finding Variable Value defined in a Script

Hi , I had a script in which there is a variable $LOG defined and I want to check where that variable is getting value from, is there a way I can check for that variable and it's value if it is defined in some other script function or script . I checked using command env and also export... (1 Reply)
Discussion started by: somu_june
1 Replies

8. Shell Programming and Scripting

Force Input in User Defined Variable

In a line such as: echo -n "How many days back would you like to check? "; read days How can I ensure that the user has a.) entered a number between 1-30 (not 0 or 31+) and b.) has not just hit enter (ie set it to "") and if it's entered wrong, how do I start the if statement over? I... (10 Replies)
Discussion started by: earnstaf
10 Replies

9. Shell Programming and Scripting

Replace variable with a user defined variable

I have a file that has a list of entries in a column x z z z x y z The column can have any length and any number of any strings. I need to replace each unique string with a user defined number. I can filter the unique entries out using awk '{if (NF==5) print $2}' file | uniq | nl >... (1 Reply)
Discussion started by: ce124
1 Replies

10. Linux

environment variable is not defined

moved to correct thread (0 Replies)
Discussion started by: alien12
0 Replies
Login or Register to Ask a Question