| Introduction | Getting Started | Using Unix | Your Environment |
Startup and Configuration Files |
Shell Variables | Commands
For more information about your Unix environment, refer to the Working Environment chapter in Unix at Fermilab.
Your environment can be customized to meet your needs and/or esthetical standards. This is usually done with the help of various startup and configuration files. These are shell scripts which typically reside in your home directory, and have their names stating with a dot (period). Files starting with a dot are called "dot files" and are not reported by an ls command, unless option -a is used, or you specifically asks for them, like ls .*
A very efficient way for a beginner to customize his/her environment is to look at other people's startup files.
The issue of login scripts is very complicated. Different shells do things very differently. Different sites require different things depending on what the system-wide ones do. However, here are a few simple suggestions:
NOTE OF CAUTION: do not redefine system commands using aliases or functions in your login scripts or elsewhere. Many scripts and programs rely upon a certain behaviors of the standard commands. Changing those behaviors can break those scripts and programs. For example, changing the cd command to echo the new location breaks the SoftRelTools build system used by D0, CDF and others. Instead, make up a new name, say, cde for cd echo.
csh (and tcsh) use three customization files. At the login time two of them are executed: .login and then .cshrc. Whenever a new shell is started, the .cshrc file is executed in the new shell. At the logout time the shell invokes .logout file.
source /usr/local/etc/fermi.login
source /usr/local/etc/fermi.cshrc
If you are thinking about using these shells, you presumably know what you are doing. For completeness, though, we mention that these shells invoke .profile file at the login time.
Korn and Bash shells execute in addition a file .kshrc and .bashrc every time a new shell is created. In fact you may customize your Korn and Bash shell environments, by invoking different startup files, depending on your need. This can be done by defining an environmental variable ENV referring to the desired file.
X Windows is very flexible and very powerful. The first relates to a large number of ways of achieving a desired goal, the second to a large number of possible configuration parameters, resources, etc. The longer you live in X environment, less confusing it becomes.
Start-up files can be categorized into:
An X Window System can be started in different ways and, sure enough, different startup files are involved. It gets complicated real fast, therefore only some hints are given here:
xclock -geom 150x150+1105+7 -hd green -hl yellow -bg pink -fg red &
xterm -ls -fn 10x20 -sb -sl 500 &
mwm
Notice that the processes are started in the background. The last line
invokes a window manager and xinit will transfer control to it.
An important variation of this method is a remote session, for example over the phone line. In this case there are two possibilities: you can run xinit on the terminal server (preferred) or on the remote node. In the latter case you will invoke xinitremote, which will execute a file .xinitremoterc. Your .xinitremoterc file may look like:
xclock -geom 150x150+1105+7 -hd green -hl yellow -bg pink -fg red &
xterm -ls -fn 10x20 -sb -sl 500
Notice that in this example you do not start a window manager, as
presumably you are running a local window manager on your X-terminal.
These are files used to customize various products, Netscape and Mosaic, editors, mail handlers, etc.. etc... They define various parameters controlling appearance and functionality of the programs, they can even define application-specific keyboard mapping, if so desired.
An important resource file is .Xdefaults. Its format is:
application_name*resource_name value
Here are some example lines from a .Xdefaults file:
emacs*font: 10x20 Mosaic*anchorColor: red 4Dwm*keyboardFocusPolicy: click
In addition to the .Xdefaults file applications may be taking their parameters from the application-specific configuration files, for example:
Configuration file Application .emacs emacs .explorerrc explorer .mh_profile MH .mailcap mosaic .piafrc piaf
This file (.mwmrc) is used to define parameters, menus, etc. for your window manager. You can define your own menus, or substitute your own programs to be invoked from the standard menus.
Shell variables are known only to the current shell. Shell variable definitions are not inherited by child processes. Any standard shell variables must be defined each time a new shell is created, typically in one's .cshrc file.
Standard D0 shell variables are defined by sourcing /usr/local/etc/d0local.cshrc. Shell variables are used to store standard options for compilation and linking. They do not normally need to be referred to by users.
The UNIX shells provide two mechanisms for defining non-shell commands -- aliases (csh/tcsh) or functions (sh/bash/ksh) and executable files. An executable file may be a script or a compiled program.
An alias is a short (one-line) command that is invoked by a specified character string and is executed by the current shell. Alias definitions are not inherited by child processes, but must be redefined in each shell, normally in one's .cshrc file.
The alias command is supported by ksh and bash, but not sh. For the entire Bourne shell family you can use shell functions instead of aliases. The format of the alias command is:
% alias = '<alias contents>'
The example below causes ls -l to be executed when the command ll is entered:
% alias ll='ls -l'
Functions (bash shell family) are declared using this syntax:
[ function ] name () { command-list; }
This defines a function named name. The word function is optional. If function is supplied the parentheses are optional. The command list is executed whenever name is specified as the name of a command.
A shell script is a file containing a number of commands that can be executed as one command. You can define variables, process arguments, define flow control, loops and conditionals, and perform I/O. It provides services like pipes, input/output redirection, variable substitution and allows you to report errors, status and results of the commands. Details depend on which shell you are using for the script.
Normally when you execute a shell script, it starts in a subshell of your current shell. At the end of the script, control returns to the parent shell, and any definitions made by the subprocess are not passed back to the parent process. If you want to execute a script in your current shell, you can use the source command:
% source scriptname
Shell scripting resources:
Executable files are executed as separate processes from the parent shell. They inherit a copy of the parent shell's environment variables (not shell variables or aliases). Since they are a separate process, they can not modify any aspect of the parent shell's variables or aliases.
| d0web-support@fnal.gov | |
| Security, Privacy, Legal | |
| Last modified: May 07, 2004 11:15:56 AM CDT | |