90 likes | 254 Views
Configuration your environment. Many user-configurable Unix programs (such as your shell) read configuration files when they start up. These configuration files contain settings and commands that determine how the programs will behave.
E N D
Configuration your environment Many user-configurable Unix programs (such as your shell) read configuration files when they start up. These configuration files contain settings and commands that determine how the programs will behave Many configuration filenames begin with a dot (.), so they are called dot files (use ls -a to see them). Often the filenames end in "rc" (for resource) Configuration files for shells are actually scripts. This means they are a series of commands written in the scripting language for the corresponding shell.
Common Configuration Files TCSH /etc/csh.cshrc Systemwide configuration file for the tcsh and csh shells. This is the first file that tcsh executes when it starts up /etc/csh.login Systemwide configuration for tcsh and csh, executed only for interactive shells. ~/.tcshrc The main personal configuration file for your tcsh shell. If tcsh doesn't find this, it looks for a .cshrc file. ~/.login This file is executed after the .tcshrc file, but only if the shell is an interactive log-in shell. It won't be used if some other process is starting the shell. ~/.logout Tcsh executes this file when you log out of an interactive shell.
BASH /etc/profile Systemwide configuration file for the bash and sh shells. ~/.bash_profile The first personal configuration file that bash looks for. ~/.bashrc This file is executed for interactive shells but not for your log-in shell (the shell that starts up when you open each Terminal window). ~/.bash_logout Executed when you log out from a bash log-in shell.
Environment Variables A variable is simply a piece of memory with a name. When the variable is used, the contents stored in memory are substituted for the name. The environment variables are managed by the shell
Common Environment Variables Variable Meaning HOME Full path of home directory. SHELL current shell USER User name PATH List of directories containing commands. LOGNAME Same as USER. PWD Full path of present working directory. MANPATH List of directories containing man pages. VISUAL Name of editor (such as vi, emacs) to be used when another program wants you edit a file.
To temporarily change or create an environment variable in tcsh (or csh): setenv VISUAL vi This sets the environment variable named VISUAL to have the value vi. Test that it worked: echo $VISUAL
To change or create an environment variable in bash (or sh): export VISUAL=vi Make sure there are no spaces on either side of the equal sign. The export command brings variables into the environment. The command line above actually combines two operations: the setting of the VISUAL variable (VISUAL=vi) and the exporting of that variable into the shell's list of environment variables. The same result could be achieved in two separate steps: VISUAL=vi export VISUAL
The Bash prompt export PS1="\[\033[1;35m\]\u\[\033[0m\] \[\033[1;34m\]\w\[\033[0m\] " Sets the user name in pink and the present working directory in blue.
Shell scripts A shell script is, as we saw in the shell configuration examples, a text file containing shell commands