LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   where a variable is stored in linux (https://www.linuxquestions.org/questions/linux-newbie-8/where-a-variable-is-stored-in-linux-727000/)

vinaytp 05-19-2009 05:51 AM

where a variable is stored in linux
 
hi all...

If i declare a variable vech=bus in terminal then i will execute export vech...i want to know where this variable is stored......


can anyone please help me.....

thanks in advance

colucix 05-19-2009 06:21 AM

They are stored in the memory allocated by a process. Environment variables are inherited by child processes and they are destroyed when the parent dies. What is the scope of this question?

vinaytp 05-19-2009 06:38 AM

i want to delete the variable declared...

rikijpn 05-19-2009 06:49 AM

use the unset command
 
You usually don't need to worry about shell variables (at least in the storage sense, for they are so tiny), but just in case; the "declare" command shows you all the variables in your shell, if you use autocompletion the list will be huge. And in order to delete a variable you can use the "unset" command.
More about unset here-> http://linux.about.com/library/cmd/blcmdln_unset.htm

colucix 05-19-2009 06:56 AM

Yes. unset should do the trick.

schneidz 05-19-2009 08:27 AM

^ does this do anything:
Code:

var=5555
echo $var
var=""


rikijpn 05-19-2009 08:44 AM

Quote:

Originally Posted by schneidz (Post 3545753)
^ does this do anything:
Code:

var=5555
echo $var
var=""


Of course it does something, it declares a null string. If you do please "declare |grep var" the variable will still be there. This is very different from "deleting" the variable.

vinaytp 05-19-2009 09:22 AM

where this declare file is stored in the system ...

rikijpn 05-19-2009 10:02 AM

What do you mean by where? What kind of answer are you looking for? A variable (in your shell, as you described), is just stored in your shell environment (your memory).

i92guboj 05-19-2009 11:03 AM

Maybe he means in-disk.

These variables are not permanently stored anywhere. You need to declare them each time. However you can use the shell initialization files for that. For example, in bash you could use /etc/profile, ~/.bashrc, ~/.bash_profile and a few others depending on the concrete circumstance when you need that variable to be set. For bash, check the "INVOCATION" section of the bash man page to know more about these rc files.

schneidz 05-19-2009 12:11 PM

Quote:

Originally Posted by rikijpn (Post 3545778)
Of course it does something, it declares a null string. If you do please "declare |grep var" the variable will still be there. This is very different from "deleting" the variable.

thanks, my guess is that instead of var taking up 4 bytes it will now take up 1 byte of ram.

can you confirm ?


All times are GMT -5. The time now is 03:39 AM.