CS155: Shells Lecture 10 - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

CS155: Shells Lecture 10

Description:

Use gzip and bzip2 to compress files and archives. ... t tab ... setenv PRINTER guitar. A .cshrc file is a shell script. ... – PowerPoint PPT presentation

Number of Views:72
Avg rating:3.0/5.0
Slides: 20
Provided by: Nat9158
Category:
Tags: cs155 | guitar | lecture | shells | tab

less

Transcript and Presenter's Notes

Title: CS155: Shells Lecture 10


1
CS155 ShellsLecture 10
2
Review
  • Use tar and zip to group a set of files into one
    archive file.
  • Use gzip and bzip2 to compress files and
    archives.
  • Use sed to do simple editing on streams of text.

3
Introduction to Shells
  • The shell manages communication between the user
    and UNIX.
  • Shells also provide facilities for completing
    tasks more efficiently
  • Environment Variables
  • Shell Variables
  • History
  • Scripting Language

4
Environment Variables
  • A variable is a symbol with an associated value.
  • Environment variables are special variables that
    are accessible globally (i.e. by all programs).
  • Environment variables are used to customize the
    behavior of the OS and many programs.
  • They are also accessible to all shells attached
    to the current login session.

5
Environment Variables
  • List current environment variables
  • printenv
  • env

gt printenv USERcs155 LOGNAMEcs155 HOME/s/bach/a
/class/cs155 PATH/s/bach/a/class/cs155/bin/usr/u
cb/bin/usr/bin/usr/local/bin/usr/local/gcc/bin
/usr/bin/X11/usr/X/bin/usr/local/java/bin/s/ch
opin/f/proj/eclipse. PWD/s/bach/a/class/cs155 GR
OUPclass HOSTpreisner LANGen_US.UTF-8 SUPPORTED
en_US.UTF-8en_USen HOSTNAMEpreisner MANPATH/u
sr/share/man/usr/man/usr/local/man/usr/local/gc
c/man PAGERless
6
Environment Variables
  • List current environment variables
  • Use to reference one of the variables
  • Use double-quotes or no quotes

gt echo I am user and my group is group I am
user and my group is group gt echo I am user
and my group is group I am cs155 and my group
is class gt echo I am user and my group is
group I am cs155 and my group is class gt echo
path /s/bach/a/class/cs155/bin /usr/ucb /bin
/usr/bin /usr/local/bin /usr/local/gcc/bin
/usr/bin/X11 /usr/X/bin /usr/local/java/bin .
7
Environment Variables
  • setenv set an environment variable
  • Note, changing PWD does not change the current
    directory.

gt printenv USERcs155 LOGNAMEcs155 PWD/s/bach/a/
class/cs155 ... gt setenv PWD /tmp gt
setenv USERcs155 LOGNAMEcs155 PWD/tmp ... gt
pwd /s/bach/a/class/cs155
8
Shell Variables
  • Shell variables are specific to a current shell
    session.
  • A shell is opened when you login, but also at
    other times such as when running typescript.
  • Some shell variables overlap with environment
    variables. Their values are generally inherited
    from the environment.

9
Setting Shell Variables
  • set can be used to list and change shell
    variables
  • Changing prompt immediately changes the shell
    prompt.

gt set path (/s/bach/a/class/cs155/bin /usr/ucb
/bin /usr/bin /usr/local/bin /usr/local/gcc/bin
/usr/bin/X11 /usr/X/bin /usr/local/java/bin
/s/chopin/f/proj/eclipse .) prompt gt shell
/usr/local/bin/tcsh term xterm tty
pts/2 uid 2543 user cs155 ... gt set prompt
hello, beautifulgt hello, beautifulgt
10
Common Variables
  • history number of lines to keep in history
  • home current working directory on login
  • path list of directories in which to search for
    executables
  • shell path of the shell executable
  • prompt the text displayed on prompt
  • user the current username

11
On/Off Variables
  • Some shell variables do not have values but
    affect programs by the existence or lack of
    existence.
  • These variables can be turned on by
  • set var
  • and turned off by
  • unset var

12
Quoting and Shell Variables
  • The symbols n and are special symbols
    interpreted by the shell
  • n references your login name
  • references your current pwd

gt set promptuser PWDgt user PWDgt set
promptuser PWDgt cs155 /s/bach/a/class/cs155gtc
d .. cs155 /s/bach/a/class/cs155gt cs155
/s/bach/a/class/cs155gtset promptn gt cs155
/s/bach/a/classgtcd cs155 gt
13
Escape Sequences
  • Escape sequences are special characters that
    stand for difficult to type character codes.
  • \n new line
  • \t tab
  • Escape sequences are often used with echo or
    other output functions to format the output
    string.

14
.login and .cshrc files
  • Two files exist to set shell variables upon
    login .login .cshrc
  • .login gets execute only when a new terminal
    session is started
  • .cshrc is executed every time a new shell is
    opened

15
.forward
  • If you dont check your mail on your CS account,
    forward your mail!
  • .forward file
  • One line in the file email address

16
alias
  • alias sets a string to be equivalent to a command
    (usually with options)
  • unalias removes the alias from a string

gt alias rmj rm . dir (ls -Alg) help
man l. ls -d . --colortty la ls
-AlgF ll ls -l --colortty mlprint mp -o -l
! lpr -h mprint mp -o ! lpr -h pprint
(enscript -Gh -fNewCenturySchlbk-Roman8
-FTimes-Bold9) print lpr -h vi vim rmj
rm . gt unalias rmj
17
umask
  • umask sets the default permissions for new files.
  • The default permissions are
  • specified by a 3 digit number.
  • Example umask 017
  • 017 ? 000 001 111
  • ? 111 110 000 (complement the digits)
  • ? rwx rw- ---
  • So, the default permission is urwx, grw

18
Your .cshrc file
unalias ls set path ( HOME/bin /usr/ucb /bin
/usr/bin /usr/local/bin /usr/local/gcc/bin
/usr/bin/X11 /usr/X/bin /usr/local/java/bin
/s/chopin/f/proj/eclipse .) set the default
permissions umask 077 alias dir ls
-Alg alias la 'ls -AlgF' alias help
man setenv PRINTER guitar
  • A .cshrc file is a shell script.
  • at the beginning of a line signifies that the
    line is a comment and should be ignored by the
    shell.

19
Summary
  • Shells can be customized using Environment and
    Shell variables.
  • To use the value of a particular variable in a
    command put a at the beginning of the name.
  • Shell variables are treated differently inside
    and .
  • .login and .cshrc are shell scripts executed on
    logging in or starting a new shell.
Write a Comment
User Comments (0)
About PowerShow.com