Wednesday, July 19, 2006


.bashrc - Making Permanent Changes

Some commands only affect the current session
Some commands only change the system temporarily, for the duration of the current session. Upon logging out, they are lost.

Two commands which behave in this fashion are export and alias.
Being unaware of this may lead the user to assume that previous safeguards are still in place, although in point of fact they won't be. Thought my change of rm (through alias; see post on 'alias'), to make it prompt me before removing, was hard-wired. As it wasn't, was less careful about removing than I could have been...
Not only safeguards are lost, of course. Also changes meant to tweak the system to the user's convenience are lost beyond the current session. How to set this straight?

In order to hard-wire any changes wrought by alias, export and others of their temporary ilk, it is necessary to put said commands in .bashrc.
.bashrc is a shell script in your home directory which is executed autmatically every time the shell starts (upon login).

First, open .bashrc:
jackn@Phoenix:~$ gedit .bashrc

In .bashrc, find the proper section. Use 'search' to find the 'alias' section, towards the end. The 'variable' section seems to be at the beginning.
Make the changes:

# Customized: An alias for rm to make it prompt the user for confirmation
alias rm='rm -i'

As in all shell scripts, the # in the first line means the following is a comment intended for the user, not a command to be run by the shell.
In the second line, the command figures exactly as it would in terminal.
It is easy to reset the shell to its default state before the changes. Just 'comment out' any changes in .bashrc by adding # at the beginning of the line. This leaves the change in the file, in case you want to apply it again, but the change is not applied by Bash:

# Customized: An alias for rm to make it prompt the user for confirmation
# alias rm='rm -i'

Generalizing changes to all the users?
The above changes will only apply to the user the .bashrc of whose home directory was changed. For changes to apply to other users, it is necessary to modify a system-wide file, or to leave each user to make changes in their .bashrc file, as they please. The system-wide file might be /etc/bash.bashrc, but haven't tested it yet.

wow gold opportunity!
Post a Comment

Links to this post:

Create a Link

<< Home

This page is powered by Blogger. Isn't yours?