Customizing the environment The different shells - PowerPoint PPT Presentation

1 / 54
About This Presentation
Title:

Customizing the environment The different shells

Description:

sh (Bourne), ksh (Korn), bash (Bourne Again), csh (C-shell), tcsh ('T' shell) are options ... Set and unset Korn shell attributes $ set -o lists attributes and ... – PowerPoint PPT presentation

Number of Views:132
Avg rating:3.0/5.0
Slides: 55
Provided by: rml6
Category:

less

Transcript and Presenter's Notes

Title: Customizing the environment The different shells


1
Customizing the environmentThe different shells
  • Chapter 17 in Textbook

2
Which shell?
  • User can choose his/her shell of preference
  • sh (Bourne), ksh (Korn), bash (Bourne Again), csh
    (C-shell), tcsh (T shell) are options
  • Commonly divided into Systems programming and
    Application programming shells

3
Which shell? Differences
  • Each shell has internal (built-in) and external
    command that might behave somewhat different
  • Environment variables further modify the behavior
    of each shell
  • Shell is your interface with the Kernel, so
    choose one that suits your style

4
Find the differences
  • The chsh (change shell) command is available in
    some systems to change your default shell
  • Not in apache.utdallas.edu.Contact your
    Administrator to change your default shell, but
    first test drive it
  • ksh and csh will be covered here

5
Systems vs. application
  • sh (Bourne)
  • ksh (Korn)
  • csh (C)
  • tcsh (T)

bash (Bourne again)
6
Korn Shell (ksh)
  • Created by David Korn under contract for ATT in
    1985.
  • Incorporates the syntax of Bourne Shell for most
    portability (superset)
  • Is the fastest for executing scripts (500 more
    than csh and up to 15000 more than Bourne)

7
ksh Features
  • String functions similar to BASIC
  • Variable typing (string, int, right-just, etc)
  • Variable assignment (value when declared)
  • Automatic menu creation function (select)
  • Functions
  • Arithmetic evals (increment and decrement)
  • Command editing using vi(1) or emacs(1G)

8
Running/exiting ksh
  • In order to run a ksh you type it in the command
    line
  • ksh
  • To return to your original shell
  • exit

9
Variables
  • Assigning a value
  • VAR110
  • VAR1VAR2
  • Null value, useful for testing conditions
  • VAR2
  • To view the contents
  • print VAR1
  • 10
  • Environment variable
  • PATHPATH/usr/bin
  • Note no spaces allowed around

10
Exporting variables
  • var110
  • print var1
  • 10
  • ksh
  • print var1
  • exit
  • export var1
  • export var220
  • ksh
  • print var1 var2
  • 10 20

null value
set and export in the same line
11
set command
  • View a list of local and environment variables
    values
  • set
  • PATH /usr/bin..
  • var10
  • Set and unset Korn shell attributes
  • set -o lists attributes and their
    state (on/off)
  • set -o option enables the option
  • set o option disables the option

12
set command
  • To automatically export all new variables
  • set -o allexport
  • To disable the automatic export
  • set o allexport

13
History
  • Keeps a list of executed commands
  • Allows the re-execution of commands
  • Allows modification prior to re-execution
  • Keeps history between sessions in
  • HOME/.sh_history

14
History
  • history
  • 121 who
  • 122 ls
  • ...
  • 136 pwd
  • history -2
  • 150 vi homework
  • 151 cp homework homework.bak
  • 152 history -2
  • history 121 124
  • ...
  • history 144

Displays the last 16 by default
Displays the last n the history call
Displays a range
Displays from this number to the end
15
History variables
  • The size of the list is specified by
  • HISTSIZE100
  • An alternate history file can be specified
  • HISTFILE.hist

16
Re-executing commands
  • Last command
  • r
  • Last command starting with a c
  • r c
  • Re-executing a command using a specific history
    number
  • r 189

17
Command line editing
  • Fix and re-execute the last command
  • ls myfle
  • myfle no such file or directory
  • r flfil
  • ls myfile
  • myfile
  • Using the history number
  • r libbin 211
  • /usr/bin/X11/xcalc

18
Setting vi to scroll through commands
  • set VISUALvior set o vi
  • Use or k
  • to move backward
  • Use or j to move forward
  • Press enter to re-execute the command

19
vi to edit commands
  • 0 moves to the beginning of the line
  • moves to the end of the line
  • l moves the cursor to the right
  • h moves the cursor to the left
  • a appends after the cursor
  • i inserts before the cursor

20
Aliasing
  • Set a new alias
  • alias rmrm i
  • Check for existing aliases
  • alias
  • Aliases can be configured in one of two files
  • HOME/.profile
  • HOME/ENV

21
Aliasing
  • Turn off aliasing for one occurrence
  • \rm file
  • Unset all aliases
  • unalias a
  • Unset a specific alias
  • unalias rm

22
Search order
  • Alias
  • Built-in command
  • Functions
  • Hash list
  • PATH variable

23
cd capabilites
  • cd to previous directory
  • cd -
  • cd shorthand
  • cd /home/lee/programs
  • cd lee paty
  • cd /home/paty/programs

24
CDPATH variable
  • export CDPATH .../
  • pwd
  • /home/paty
  • cd bin
  • /home/paty/bin
  • cd etc
  • /etc
  • cd bin
  • /bin

25
Tilde ()
  • cd current user is lee
  • pwd
  • /home/lee
  • cd paty paty being a valid user
  • pwd
  • /home/paty
  • cd /bin a directory under lees
    home
  • pwd
  • /home/lee/bin

26
Filename expansion
  • Set
  • VISUALvi
  • or
  • set o vi
  • Type the partial name and then use thesequence
    \
  • For a list of options, use

27
I/O redirection
  • Input and output redirection is standard across
    shells
  • ls l list
  • ls l list
  • sort

28
Standard error
  • Write the errors to a file
  • find / -name test 2 error-file
  • Write the errors to a terminal
  • find / -name test 2 /dev/pts/130
  • Throw away the errors
  • find / -name test 2 /dev/null

29
Standard output and standard error
  • To different files
  • find / -name test results 2 errors
  • To the same file
  • find / -name test results 21

30
ksh configuration files
  • /etc/default/login
  • Configures basic settings for all users (path,
    umask)
  • /etc/profile
  • Configures basic settings for all ksh users
    (PATH, umask, mail)
  • HOME/.profile
  • Configures settings for each new ksh (set calls)
    if it exists. Analogous to .login in csh
  • HOME/ENV
  • Configures settings for Korn shell once at login
    (alias, history, prompt). Analogous to .cshrc

31
C-Shell
  • Developed by Bill Joy at U.C. Berkeley
  • Same functionality and programming constructs of
    Bourne Shell, different keywords
  • First shell focused on interactivity

32
csh vs sh
  • csh Added
  • command aliasing
  • command history
  • command editing
  • job control

33
running C-Shell
  • C-shell was created as the default user shell
    in some versions of Unix (now bash holds that
    title)
  • In order to run a csh you type it in the command
    line
  • csh

34
csh local variables
  • To set the value
  • set prompthostname -s
  • set noclobber
  • set var1var2
  • set path (path /usr/bin)

35
csh local variables
  • To list local variables
  • set
  • To unset a variable
  • unset noclobber

36
csh environment variables
  • To set the value of an environment variable
  • setenv DISPLAY 139.1.2.30.0
  • List variables and their values
  • env
  • printenv
  • Unset a variable
  • unsetenv DISPLAY
  • Note No equal sign is necessary (common error)

37
csh predefined variables
  • System-defined local variables
  • Some need to be enabled, others need a value
  • Enable filename completion
  • set filec
  • Store the last 50 commands
  • set history50

38
History
  • csh history can be used to
  • Re-execute previous commands with or without
    changes
  • Reduce the amount of keystrokes
  • To enable history we simply assign a value
  • set history50

39
History
  • When we logout, history is lost
  • To keep all or a portion of it
  • set savehist50
  • History is between sessions is kept in
  • HOME/.history

40
How to use history
  • Can view portions of the list
  • To view the last 3 commands
  • history 3
  • 96 ls
  • 97 who
  • 98 pwd

41
Re-execute the last command
!!
!-2
Re-execute the second tothe last command
!97
Re-execute the command at entry 97 in the history
!cd
Re-execute the last commandstarting with cd
42
Command line editing
  • ls myfle
  • myfle no such file or directory
  • flfil
  • ls myfile
  • myfile

43
Alias command
  • An alias is an alternative name (usually shorter)
    to
  • Create customized commands
  • Execute multiple commands with fewer keystrokes
  • Speed up commonly executed tasks

44
Alias syntax
  • Creating an alias Disabling alias once
  • alias rm rm i \rm
  • Displaying existing aliases
  • alias
  • rm (rm i)
  • Eliminating a specific alias
  • unalias rm
  • Eliminating all aliases
  • unalias

45
Search order
  • Aliases
  • Built-in commands
  • Hash list (list of previous path searches)
  • Path

46
Using History with alias
  • History events fields are separated by white
    space
  • 98 cp r project1/status /usr/martha/status
  • You can use this field numbering scheme to create
    an alias with user arguments.
  • alias loc find \!2 name \!1

0 1 2
3
47
The special character
  • An abbreviation of a users home directory
  • It is used in one of two ways
  • Change to joes home directory
  • cd joe
  • Change to the home directory of the account used
    for login
  • cd

48
Filename Completion
  • To enable filename completion
  • set filec
  • Filename completion allows the C shell to
    complete the name of a file or directory
  • Use the ESC key for name completion
  • Attempts to match the unique character pattern
    provided by the user
  • Use Ctrl-D when signals a non-unique
    pattern.

49
C-shell Special characters
  • works as an abbreviation
  • chmod ugo-w proj1,12/goals
  • Instead of
  • chmod ugo-w proj1/goals proj12/goals

50
Redirecting Standard Input and Output
  • Standard across shells
  • mail bob
  • cat file1 file2 file3 files
  • cat file4 files

51
clobbering
  • Redirecting the output to an existing file
    destroys (clobbers) the contents of the file
  • Use to append information
  • Set the noclobber local variable to prevent
    accidental clobbering
  • set noclobber
  • cat memo1 memo2 memo3 files
  • Files File exists
  • Use the ! Symbol override noclobber
  • cat header file1 ! files

52
Redirecting Standard Error
  • Send both output and errors to the same file
  • find / -name letter /find.out
  • Send standard output and errors to different
    files
  • (find / -name letter /find.out) find.errs

53
Redirecting Standard Error
  • Send the output to the terminal screen (window),
    and errors to /dev/null
  • (ls -R /dev/tty) /dev/null
  • Send the output to find.out and errors to the
    "bit bucket"
  • (find / -name letter /find.out) /dev/null

54
C Shell Configuration Files
  • /etc/default/login
  • Configures basic settings for all users (path,
    umask)
  • /etc/cshrc
  • Configures basic settings for all C shell users
    (motd, mail)
  • HOME/.cshrc
  • Configures settings for each new C shell (alias,
    history, prompt)
  • HOME/.login
  • Configures settings for C-shell once at login
    (environment variables, i.e DISPLAY)
Write a Comment
User Comments (0)
About PowerShow.com