Setting Up Your Environment Environment Variables Aliases Setup - - PowerPoint PPT Presentation

setting up your environment
SMART_READER_LITE
LIVE PREVIEW

Setting Up Your Environment Environment Variables Aliases Setup - - PowerPoint PPT Presentation

Setting Up Your Environment Environment Variables Aliases Setup Files .login .tcshrc other .*rc files History Command Completion Environment Variables (35.3) Unlike a regular shell variable, an environment


slide-1
SLIDE 1

Setting Up Your Environment

  • Environment Variables
  • Aliases
  • Setup Files

– .login – .tcshrc – other .*rc files

  • History
  • Command Completion
slide-2
SLIDE 2

Environment Variables (35.3)

  • Unlike a regular shell variable, an environment

variable is inherited by another shell or program that you start.

  • A Unix process 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 C program.

int main(int argc, char *argv[], char *env[]);

slide-3
SLIDE 3

Setting Environment Variables (35.3)

  • General form. In the csh or tcsh, 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 <name> <value>

  • Examples:

setenv EDITOR vi setenv DISPLAY lov301:0.0

slide-4
SLIDE 4

Unsetting Environment Variables

  • Sometimes it is desirable to undefine an

enviroment variable. You can do this with the unsetenv command.

  • General form.

unsetenv <name>

  • Examples:

unsetenv EDITOR unsetenv DISPLAY

slide-5
SLIDE 5

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 print out the variables using a

printenv command.

printenv [<environment variable name>]

  • You can always display a specific environment

variable using:

echo $<environment variable name>

slide-6
SLIDE 6

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 which the shell looks to find commands.

– EDITOR: Name of your favorite editor. – PRINTER: Name of your default printer. – PWD: Contains the absolute pathname of your current

  • directory. Set by the cd command.

– HOME: Contains the absolute pathname of your

home directory.

slide-7
SLIDE 7

Predefined Environment Variables (cont.)

– SHELL: Contains the absolute pathname of your

shell.

– USER: Contains your username. – TERM: Contains the name of your terminal type. – DISPLAY: Used by the X Window system to identify

the display server.

slide-8
SLIDE 8

Aliases (29.2, 29.3)

  • The alias facility allows you to define

abbreviations for commands.

  • General form.

alias <name> <string>

  • Examples:

alias lprd “lpr -Z duplex” alias ls “ls -F” alias web “ssh websrv.cs.fsu.edu”

slide-9
SLIDE 9

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 sort

  • Related commands:

whatis – print a one line summary of the command whereis – locate the binary, source, and man pages for a command alias – without the string definition, it prints the current alias for a command

slide-10
SLIDE 10

Removing Aliases

  • The unalias command allows you to remove

aliases that were previously specified.

  • General form.

unalias <name>

  • Examples:

unalias ls unalias web

slide-11
SLIDE 11

Setting Your Command Prompt (4.1)

  • You can set your prompt at the command line.
  • General form.

set prompt = <string>

  • Examples:

set prompt = “csh% ” set prompt = “`hostname`% “

slide-12
SLIDE 12

Source Command (35.29)

  • It would be desirable to create a shell script that

defines your environment variables and aliases. But invoking a shell script creates a child process and thus the script cannot update the environment variables or aliases of the parent process.

  • The source command (csh and tcsh) reads a script

file into the current shell instead of starting a child shell. All definitions of variables and aliases are retained. source ~/.tcshrc

slide-13
SLIDE 13

Shell Setup Files (3.3)

  • Shell setup files are invoked automatically at the

start of specific events.

  • Types:

– .login – .tcshrc – other .*rc files

slide-14
SLIDE 14

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 wish to run once each

time you login.

  • Check news, mail, calendar, etc.
slide-15
SLIDE 15

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)

slide-16
SLIDE 16

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 more complex applications may have a setup subdirectory off of your home directory.

slide-17
SLIDE 17

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
slide-18
SLIDE 18

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.

slide-19
SLIDE 19

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.

slide-20
SLIDE 20

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.

slide-21
SLIDE 21

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

slide-22
SLIDE 22

History (30.1)

  • Most shells contain a history of your most

recently entered commands.

  • You can retrieve these commands, make changes,

and reexecute them.

  • You can set the number of commands to save in

your history in your .tcshrc file.

set history=<number>

slide-23
SLIDE 23

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

slide-24
SLIDE 24

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

slide-25
SLIDE 25

Extracting Portions of Last Command Exs

# using the last argument from the previous command ps2pdf t.ps t.pdf acroread !$ # using argument 1 from the previous command cp 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 chmod +x ns.sh nd.sh ir.sh pd.sh pf.sh lpr !:2*

slide-26
SLIDE 26

Shell Command-Line Editing (30.14)

  • The tcsh allows you to use the arrow keys and
  • ther 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

slide-27
SLIDE 27

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 path

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.