tcsh csh on Steroids - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

tcsh csh on Steroids

Description:

Like the Korn shell, tcsh provides an emacs and vi command-line editing mode ... One advantage over Korn shell editing is that you are always in the command-line ... – PowerPoint PPT presentation

Number of Views:155
Avg rating:3.0/5.0
Slides: 26
Provided by: Kenneth4
Category:
Tags: csh | korn | steroids | tcsh

less

Transcript and Presenter's Notes

Title: tcsh csh on Steroids


1
tcshcsh on Steroids
2
tcsh
  • Derived from csh, Bill Joy's creation from
    Berkeley
  • Based on Joy's original source, many, many people
    have added to it since
  • Over 50 names are listed as contributors in the
    6.08 man page
  • Freely available over the internet
  • Compatible with csh
  • All the commands and capabilities you are used to
    in csh are available in tcsh
  • If it works in csh, it should also work in tcsh

3
The 't' in tcsh
  • In 1964, DEC produced the PDP-6.
  • The PDP-10 was a later re-implementation that
    was re-christened the DECsystem-10 in 1970 or
    so when DEC brought out the second model, the
    KL10.
  • TENEX was created at Bolt, Beranek Newman
  • A Cambridge, Mass. think tank also referred to
    as BBN, one of the early implementers of the
    Internet
  • Done in 1972 as an experiment in demand-paged
    virtual memory operating systems.
  • They built a new pager for the DEC PDP-10
    and created the OS to go with it.
  • It was extremely successful in academia.

4
  • In 1975, DEC brought out a new model of the
    PDP-10, the KL10
  • Intent was to have only a version of TENEX, which
    they had licensed from BBN, for the new box,
    which they called TOPS-20 (the capitalization
    is trade-marked).
  • A lot of TOPS-10 users (The OPerating System
    for PDP-10') objected thus DEC found themselves
    supporting two incompatible systems on the
    same hardware--but then there were 6 on the
    PDP-11!

5
  • TENEX, and TOPS-20 up until version 3, had
    command completion via a user-code-level
    subroutine library called ULTCMD.
  • With version 3, DEC moved all that capability and
    more into the monitor ('kernel' in Unix lingo)
  • The creator of tcsh was impressed by this feature
    and several others of TENEX and TOPS-20, and
    created a version of csh which mimicked them.

6
Advantages of tcsh over csh
  • Command-line editing
  • Better word completion
  • tcsh can complete command and variable names in
    addition to filenames
  • Spelling correction
  • Assistance for entering hard to type filenames
  • Built-in rm detection

7
Startup and Configuration Files
  • /.cshrc - Read at startup
  • /.tcshrc - Read at startup instead of ./cshrc
  • if it exists
  • /.login - Read by login shells at startup
  • /.history - Saves command history list
  • /.cshdirs - Saves the directory stack
  • /.logout - Read by login shells at termination

8
Command-line Editing
  • Like the Korn shell, tcsh provides an emacs and
    vi command-line editing mode
  • Selected by "bindkey -e" or "bindkey -v" command
  • Generally placed in your /.tcshrc file
  • One advantage over Korn shell editing is that you
    are always in the command-line editor!
  • Normal mode is insert, which is how you enter
    commands
  • Various editing commands are available in insert
    mode

9
Insert Mode Editing Commands
  • CTRL-B Move cursor back one char
  • CTRL-F Move cursor forward one char
  • CTRL-A Move to beginning of line
  • CTRL-E Move to end of line
  • CTRL-H or DEL Delete char to left of cursor
  • CTRL-W Delete word backward
  • CTRL-U Delete from beginning of line
  • to cursor
  • CTRL-K Delete from cursor to end of
  • line

10
Command Mode
  • Use ESC to enter command mode
  • Normal vi commands are then in effect
  • Don't forget to issue the "bindkey -v" command
    first or things will act very confusingly!
  • You can also use the command editor to retrieve
    and execute commands from the history list
  • CTRL-P (previous) and CTRL-N (next) are used to
    move up and down through the history list
  • ? and / can also be used to search backwards and
    forwards through the history list

11
Repeating Commands in a Loop
  • If you want to run a command once for each of a
    set of filenames, you can use a foreach loop
  • foreach fn (file1 file2 file3 file4)
  • ? cat fn spell fn.spl
  • ? end
  • After you enter the foreach line, the shell
    changes the prompt as it collects the body of the
    loop and then executes it after the end is
    entered

12
Word Completion
  • In csh if filec is set, it will attempt to
    complete filenames for you when you hit the TAB
    key
  • If the prefix you type is ambiguous, CTRL-D will
    list all potential matches
  • In tcsh, command completion is always active
  • To exclude certain filename suffixes from being
    considered, set fignore ( .o .bak ) in your
    /.tcshrc file

13
Patterns
  • You can use patterns (, ?, ) to define
    filenames
  • tcsh also adds and pattern
  • You can also use patterns for filenames that
    don't exist
  • The are used for specifying non-existent
    files
  • For example
  • mkdir tempdir1-4
  • mkdir No match
  • However
  • mkdir tempdir1,2,3,4

14
Assistance in Entering Difficult Filenames
  • Filename completion is usually the easiest way to
    deal with difficult to type filenames
  • tcsh uses a backslash (\) to escape special
    characters
  • For example, with a file named "My Favorite Lab
    Pt II"
  • mv My Hit TAB
  • mv My\ Favorite\ Lab\ Pt\ II tcsh provides rest
    of name
  • mv My\ Favorite\ Lab\ Pt\ my_fav_lab_2
  • Type rest of command
  • csh does not have this capability

15
-'s as Leading Chars in Filenames
  • Though not tcsh specific, how do you delete a
    file that has a leading - in it's filename?
  • Most commands see a - as signifying an option
  • rm -filename
  • usage rm -rif file
  • Hmmm

16
  • Easiest way is usually to preface the filename
    with its path
  • rm ./-filename
  • The character can cause the same kind of
    problems

17
Spelling Correction
  • To enable spelling correction, add one of the
    following to /.tcshrc
  • set correct cmd
  • set correct all
  • The first option causes spelling correction to be
    applied for commands only
  • The second tries to correct all entries on the
    command line
  • You need to be careful with correct all

18
  • When the shell thinks you have misspelled a word,
    it suggests a correction
  • mroe lab3
  • CORRECTmore lab3 (ynea)?
  • yesnoeditabort
  • Now, suppose I enter the following command
  • mv lab3 lab4
  • CORRECTmv lab3 lab3 (ynea)?
  • What is the problem?

19
Automatic rm Detection
  • If the shell variable rmstar is set, tcsh will
    detect attempts to use rm
  • rm
  • Do you really want to delete all files? n/y
  • If you want to overide it, use the force option
    with rm
  • rm -f

20
Directory Stacks
  • Moving between two directories in tcsh is simple
  • "cd -" returns you to your previous directory
  • For more control with multiple directories, both
    csh and tcsh allow a directory stack
  • pushd and popd, along with dirs are used with the
    stack
  • pushd dirname changes to that directory and
    pushes the directory onto the stack
  • popd changes to the directory on the top of the
    stack
  • dirs lists the contents of the stack without
    changing your current directory

21
  • pushd without a directory name exchanges the top
    two elements of the stack
  • You can also use pushd n to rotate the stack so
    that entry n is on top
  • If stack has dir1 dir2 and dir3, pushd 2 would
    give
  • dir3 dir1 dir2
  • popd n pops entry n from the stack, changing to
    it (tcsh only though some versions of csh may do
    it)

22
Stack Example
  • Say I start in /home/bonnie/cc9
  • pushd krf current dir is /home/bonnie/krf
  • stack krf cc9
  • pushd src current dir is /home/bonnie/krf/src
  • stack krf/src krf cc9
  • pushd java current dir is /home/bonnie/krf/src/jav
    a
  • stack krf/src/java krf/src krf cc9
  • pushd current dir is /home/bonnie/krf/src
  • stack krf/src krf/src/java krf cc9
  • popd current dir is /home/bonnie/krf/src/java
  • stack krf/src/java krf cc9
  • pushd ../C current dir is /home/bonnie/krf/src/C
  • stack krf/src/C krf/src/java krf cc9

23
  • popd current dir is /home/bonnie/krf/src/java
  • stack krf/src/java krf cc9
  • popd current dir is /home/bonnie/krf/
  • stack krf cc9
  • popd current dir is /home/bonnie/cc9
  • stack cc9

24
tcsh Specific Shell Variables
  • correct - Enable spelling correction
  • rmstar - Enable "rm " detection
  • savedirs - Save the directory stack in
  • /.cshdirs on logout
  • tcsh - Holds tcsh version number
  • version - Holds shell version and
  • configuration information

25
tcsh Prompts
  • csh didn't have a whole lot of special things you
    could put in your prompt
  • \! to add the command number followed by - was
    it!
  • tcsh adds a number of other useful options
  • t, p (T, P), D, W, and y
  • time, time plus seconds (24 hour versions), day,
    month, and year Example set prompt "The time
    is t "
  • B/b bolds/unbolds
  • U/u underlines/ends underline
  • S/s starts/ends standout
  • Other options are listed in the man page
  • Check 'em out!
Write a Comment
User Comments (0)
About PowerShow.com