<<

Setting Up Your Environment

● Environment Variables

● Aliases

● Setup Files

– .login

– .tcshrc

– other .* files

Completion Environment Variables (35.3)

● Unlike a regular variable, an is inherited by another shell or program that you .

● A cannot change its parent's environment.

● Environment variables hold information that you would normally have to commonly specify in shell commands or for Unix utilities.

● Environment information is passed to a program. int main(int argc, char *argv[], char *[]); Setting Environment Variables (35.3)

● General form. In the csh or , use the following command to set an environment variable. The general convention is to use capital letters for environment variables and lowercase letters for regular shell variables. setenv

● Examples: setenv EDITOR setenv DISPLAY lov301:0.0 Unsetting Environment Variables

● Sometimes it is desirable to undefine an enviroment variable. You can do this with the unsetenv command.

● General form. unsetenv

● Examples: unsetenv EDITOR unsetenv DISPLAY Displaying the Value of an Environment Variable

● The setenv command by itself will display the values of all of your environment variables. setenv

● You can also out the variables using a printenv command. printenv []

● You can always display a specific environment variable using: $ Predefined Environment Variables (35.5)

● Predefined means that their name and use is predefined. You still have to usually define them yourself.

– PATH: Contains a list of directories separated by colons in the shell looks to commands.

– EDITOR: Name of your favorite editor.

– PRINTER: Name of your default printer.

: Contains the absolute pathname of your current . Set by the command.

– HOME: Contains the absolute pathname of your . Predefined Environment Variables (cont.)

– SHELL: Contains the absolute pathname of your shell.

: Contains your username.

– TERM: Contains the name of your .

– DISPLAY: Used by the to identify the display server. Aliases (29.2, 29.3)

● The facility allows you to define abbreviations for commands.

● General form. alias

● Examples: alias lprd “lpr -Z duplex” alias “ls -F” alias web “ssh websrv.cs.fsu.edu” Which (2.6, 35.27)

● The which command can be used to print out the value of an alias or the pathname of a utility. which ls which

● Related commands: whatis – print a one line summary of the command the binary, source, and man pages for a command alias – without the string definition, it prints the current alias for a command Removing Aliases

● The unalias command allows you to remove aliases that were previously specified.

● General form. unalias

● Examples: unalias ls unalias web Setting Your Command Prompt (4.1)

● You can set your prompt the command line.

● General form. set prompt =

● Examples: set prompt = “csh% ” set prompt = “`hostname`% “ Source Command (35.29)

● It would be desirable to create a that defines your environment variables and aliases. But invoking a shell script creates a and thus the script cannot update the environment variables or aliases of the .

● The source command (csh and tcsh) reads a script into the current shell instead of starting a child shell. All definitions of variables and aliases are retained. source ~/.tcshrc Shell Setup Files (3.3)

● Shell setup files are invoked automatically at the start of specific events.

● Types:

– .login

– .tcshrc

– other .*rc files The .login File (3.3)

● The .login file is invoked in the csh or tcsh when you login to a Unix system.

● Tasks typically performed in a .login file include:

– Setting environment variables, which are passed to subshells automatically.

– Setting the I/O options for your terminal.

– Performing commands you to run once each you login.

● Check news, , calendar, etc. The .tcshrc File

● The .tcshrc file is run any time a tcsh shell starts. If the .tcshrc file does not exist, then the .cshrc file is invoked. The tasks performed are often those that set definitions that are not passed to subshells.

● Tasks typically performed in a .tcshrc file include:

– setting aliases

– setting your command line prompt

– setting the history variable (will be discussed later) Other .*rc Files (3.20)

● A variety of different commands use a .*rc file in your home directory to perform some type of initialization. Some applications require that you prepare the .*rc file, while others will set one up automatically for you. The complex applications may have a setup subdirectory off of your home directory. Common .*rc Setup Files

● .mailrc: used with mail and related mailers

● .gvimrc: used with the gvim editor

● .newsrc: used with news readers

● .procmailrc: autonomous mail processor

● .acrorc: used with the acroread pdf viewer

● .xfigrc: used with the xfig picture editor The .mailrc Setup File

● .mailrc: for use with mail and related mailers

– Setup aliases for email addresses.

– Setup the default editor for your mailer.

– Specify a file that records outgoing messages.

– Specify a command to print a message.

– Specify a sound when you receive a message. The .gvimrc Setup File

● .gvimrc: for use with the gvim editor (similar in purpose to the .emacs file)

– Set the background of the window.

– Set the size and type of the font.

– Set the number of width and height in characters.

– Set whether syntax highlighting is turned on or off. The .newsrc Setup File

● .newsrc: for use with news readers

● News readers allow you to read articles that are posted to particular newsgroups. One command to use is trn (threaded read news program).

● The .newsrc file is automatically created by trn if it does not find one.

● The .newsrc file is automatically read by trn and you are given the option to add new newsgroups that have been recently created. Other Common .*rc Setup Files

● Other common .*rc setup files: .pinerc – setup file the pine mailer .procmailrc – setup for the autonomous mail processor that can be used to filter spam or generate automatic replies .acrorc – setup file for the acroread pdf viewer to indicate how to display a pdf file .xfigrc – contains recently accessed files by the xfig picture editor History (30.1)

shells contain a history of your most recently entered commands.

● You can retrieve these commands, changes, and reexecute them.

● You can set the number of commands to save in your history in your .tcshrc file. set history= Command History Substitution (30.5,30.7,30.8,30.9)

● There are many options for performing command history substitution. !! repeat the last command ^pat^rep repeat last command replacing pat with rep !-n repeat the last nth previous command history display the history list of commands by number history num display the last num commands !num repeat the command numbered num !pat repeat last command that starts with pat Extracting Portions of the Last Command (30.3, 30.4, 30.8)

● You can also extract portions of the last command to be used in the current command. !$ take the last argument from the previous command !^ take argument 1 from the previous command !* take the first through the last arguments !:n* take the arguments n through the last argument from the previous command where the first argument is numbered at 0 Extracting Portions of Last Command Exs

# using the last argument from the previous command ps2pdf t. t.pdf acroread !$

# using argument 1 from the previous command t.c t.c.old vi !^

# using all of the arguments from the previous command gcc main.c input.c proc.c output.c lpr !*

# using arguments n through the last argument +x ns.sh nd.sh ir.sh pd.sh pf.sh lpr !:2* Shell Command-Line Editing (30.14)

● The tcsh allows you to use the arrow keys and other special characters to retrieve previous commands and to edit them.

● Arrow key bindings: up go back one command down go forward one command left go backward one character right go forward one character Complete Word Function (28.6)

● In the tcsh you can complete a word by pressing the TAB character if the characters typed so far are unique.

– Complete the name of command that is in your when the word is the first word on the command line.

– Complete the name of a file that is in the current or specified directory.