LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Red Hat (https://www.linuxquestions.org/questions/red-hat-31/)
-   -   changing env variables (https://www.linuxquestions.org/questions/red-hat-31/changing-env-variables-811036/)

aceone 05-30-2010 03:33 AM

changing env variables
 
hi,
I want to know two things:

1.what is the process of changing values of environment variables
like we use set $VARIABLE=value. then why we log off?if possible plz explain the steps and why we do so

2.How do I change size of HISTORY?I changed HISTSIZE in /etc/profile to "5",when i execute "history" it shows last "5" commands.I wanted to limit total number of commands in history to be 5.

Thanks & regards

catkin 05-30-2010 03:40 AM

Which shell are you using?

aceone 05-30-2010 03:52 AM

I am using bash ,RHEL5

Robhogg 05-30-2010 04:38 AM

The simplest way, if you want to set it just for your users, is to edit the .bashrc file in your home directory, and add the lines to set the variable to this:

Code:

VARIABLE=value
export VARIABLE

If you wanted to do it for all users, you could add the lines to /etc/profile.

aceone 05-30-2010 10:09 AM

still not clear :(

Robhogg 05-30-2010 11:48 AM

There are actually separate environment variables for the length of the history list in the shell (HISTSIZE), and the number of commands stored in .bash_history on exit(HISTFILESIZE), so you might want to set both of these. From man bash:

Code:

HISTFILESIZE
      The maximum number of lines contained in  the  history  file.
      When  this  variable is assigned a value, the history file is
      truncated, if necessary, by removing the oldest  entries,  to
      contain no more than that number of lines.  The default value
      is 500.  The history file is  also  truncated  to  this  size
      after writing it when an interactive shell exits.
HISTSIZE
      The number of commands to remember  in  the  command  history
      (see HISTORY below).  The default value is 500.

For shell variables, you only add the $ symbol when you are accessing the value stored (dereferencing). To assign a value to a variable, you use the name on its own:

VARIABLE=value # set the value

echo $VARIABLE # access it again

To then make a variable into an environment variable, you need to export it (which again uses the name on its own):

export VARIABLE

To set environment variables permanently for user(s), you can add the assignment and export statements to one of the following files:
  • /etc/profile - sets defaults for all users
  • /home/<username>/.profile - read when a user logs in, used by all shells (not just bash)
  • /home/<username>/.bashrc - read whenever a new bash session is started, but used only by bash

Changes might not take effect until you've logged out and in again.

Is that any clearer?

Rob

aceone 05-31-2010 03:52 PM

crystal clear :)
thanks

cepal 06-25-2012 06:13 AM

related question
 
Lo,
I've go a related question - http://www.linuxquestions.org/questi...ns-4175413246/ .
The thing is, how do I change (in my particulare case HISTSIZE and HISTFILESIZE :-) ) to all currently running sessions of a particular (generic) user without actually telling the people using it to do it manually. Can root simply write to /proc/[PID]/environ? Yet I didn't find HISTSIZE in that environ file (how comes?)...

Thanks.


All times are GMT -5. The time now is 10:45 PM.