Pages

Thursday, July 24, 2014

Customizing the UNIX User Environment - Part 1 - UNIX shell configuration files - Part 2

Customizing the UNIX User Environment

**********************************************************************************

UNIX shell configuration files

**********************************************************************************

 

Configuring user profiles

----------------------------------------

The file that most directly affects a user's experience of a shell is the .profile file located in a user'a home directory.

This file contains variables and commands that relate to how a user's shells will look and respond

 

Following is an example of a Bash shell .profile file.

 

bash-2.05a# cat .profile

#variables

SHELL=/bin/bash              #specifies path to the executable file for this shell

ENV=$HOME/.bashrc

PS1=$PWD

PATH=/usr/java/j2sdk_1_4_01/bin:$PATH

bash-2.05a#

 

Any line of text in a .profile file that begins with a hash (#) is a comment and the system ignores it.

Note: There are no mandatory .profile variables. Each variable shown here is an example, and is not strictly required to run a functional system.

 

ENV vairable specifies the path to the script that will be run for every subsequent instance of this shell-such as non interactive subshells launched by other scripts. It references the path value stored in the shell variable HOME - set elsewhere - by placing a dollar symbol ($) in front of the variable name.

 

The PS1 variable specifies the text that should be displayed as a prompt. In this case, it references the value stored in the PWS global variable, which is the path to the current working directory

 

The PATH variable specifies paths for the system to search for executables binaries. The PATH variable is normally set in the /etc/profile file. In this case, the value of the PATH variable is appended with additional information specifically for this user.

 

Followin gis a sample .bashrc file. which would normally be referenced by the EBV variable in a user's .profile file.

 

bash-2.05a# cat .bashrc

#Aliases

alias f=finger

alias fun=/usr/games

bash-2.05a#

 

Note : There are no mandatory .bashrc commands. Each command shown here is an example, and is not stricly required to run a functional system.

 

This .bashrc file contains alias commands that allow you to assign a shortcut name to a command or path, to minimize typing.

The first command assigns an alias of "f" to the finger command, which means you could now execute the finger command simply by typing f.

If the target of an alias consists of more than a single word, you should enclose it in single quotes.

 

The next alias command assigns an alias of "fun" to the path /usr/games. This means you could now navigate to that path by typing cd fun.

 

Alias commands can be executed from the shell prompt.

When the target of an alias is longer than a single word, you need to remember to enclose it in single quotes. In this case, the full statement reads as folloes:

alias list = 'ls -l|more'

 

Summary

--------------

A shell provides an interface for users to interact with the kernel. You configure shells using the /etc/profile and .profile files.

The .profile file contains variables and commands that configure a specific user's shell, but the file is usualy only referenced at login. Any commands that should be executed for every script should be placed in a separate file and referenced using the ENV variable.

No comments:

Post a Comment