Chapter 9: The TC Shell Everything you thought you knew is now wrong.

Slides:



Advertisements
Similar presentations
Chapter Seven Unix Shell Environments1 System Programming UNIX Shell Environments.
Advertisements

CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Linux+ Guide to Linux Certification, Second Edition
CS 497C – Introduction to UNIX Lecture 36: - Customizing the Environment Chin-Chih Chang
Scripting Languages and C-Shell. What is a scripting language ? Script is a sequence of commands written as plain text and run by an interpreter (shell).
1 UNIX essentials (hands-on) the directory tree running programs the shell (using the T-shell) → command line processing → special characters → command.
Shell Script Examples.
CTEC 1863 – Operating Systems Shell Scripting. CTEC F2 Overview How shell works Command line parameters –Shift command Variables –Including.
Lecture 3  Shell Variables  Shell Command History  Job / Process Control  Directory Control.
Chapter 15 Introductory Bash Programming
Welcome to CSE  Name: Di Cao   Classroom: DL357  Class Time: T 8:30am - 9:18am  Office.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
An Introduction to Unix Shell Scripting
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
1 UNIX essentials (hands-on) the directory tree running programs the shell → command line processing → special characters → command types → shell variables.
Shell Script Programming. 2 Using UNIX Shell Scripts Unlike high-level language programs, shell scripts do not have to be converted into machine language.
UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.
Introduction to Linux OS (IV) AUBG ICoSCIS Team Prof. Volin Karagiozov March, 09 – 10, 2013 SWU, Blagoevgrad.
LINUX System : Lecture 6 Shell Programming
Linux+ Guide to Linux Certification, Third Edition
Linux Operations and Administration
Basic Shell Scripting - Part 1 Objective - Learn to: Read Start-up Files Edit Start-up Files Modify Your User Environment Communicate with Users Write.
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
1 Homework / Exam HW7 is due next class Starting Glass chapter 4 and parts of 7 Exam 3 – Class 26 –Open Book / Open Notes –Up through End of K&R Chapter.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
Workbook 6 – Part 2 The Bash Shell
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
CSCI 330 T HE UNIX S YSTEM C Shell. C S HELL SPECIFICS Startup and initialization Shell variables Prompt Alias Redirections and pipe 2 CSCI The.
Introduction to Unix Shell & Scripting with csh/tcsh  Brief Unix History  Unix Shell & Flavor  CSH/TCSH Scripts.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
Chapter 10: BASH Shell Scripting Fun with fi. In this chapter … Control structures File descriptors Variables.
Adv. UNIX:CShell/71 Advanced UNIX v Objectives of these slides: –introduce the C Shell –concentrate on features not in the Bourne Shell (but many.
June 1, 1999Customizing the UNIX Environment1 Introduction to UNIX G. Customizing the UNIX Environment.
UNIX shell environments CS 2204 Class meeting 6 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Customizing the Shell Environment. UNIX Shells Two characteristics of shells –Interactive: prompts ($) and waits for your response/requests –Noninteractive:
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Chapter 5: The Shell The Man in the Middle. In this chapter … The command line Input, output, and redirection Process management Wildcards and expansion.
CSCI 330 UNIX and Network Programming Unit III Shell, Part 1.
Chapter 8: The Bourne Again Shell It’s a command interpreter, it’s a programming language, and it makes a mean martini.
Jozef Goetz, expanded by Jozef Goetz, 2006 Credits: Parts of the slides are based on slides created by textbook authors, Syed M. Sarwar, Robert.
Unix Advanced Shells Chapter 10. Unix Shells u Command Line Interpreter –once logged in, login gives control to a shell –it prompts for input, then parses,
Linux+ Guide to Linux Certification, Second Edition
Introduction to Bash Shell. What is Shell? The shell is a command interpreter. It is the layer between the operating system kernel and the user.
Configuration your environment Many user-configurable Unix programs (such as your shell) read configuration files when they start up. These configuration.
1 © 2012 John Urrutia. All rights reserved. Chapter 09 The TC Shell.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
Lesson 8-Specifying Instructions to the Shell. Overview An overview of shell. Execution of commands in a shell. Shell command-line expansion. Customizing.
1 Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
Linux Administration Working with the BASH Shell.
ULI101 Week 10. Lesson Overview ● Shell Start-up and Configuration Files ● Shell History ● Alias Statement ● Shell Variables ● Introduction to Shell Scripting.
Implementation of a simple shell, xssh
SUSE Linux Enterprise Desktop Administration
Introduction to Shells
Shell Features CSCI N321 – System and Network Administration
Implementation of a simple shell, xssh (Section 1 version)
Implementation of a simple shell, xssh
Shell Environments.
UNIX and Shell Programming (06CS36)
John Carelli, Instructor Kutztown University
Linux Shell Script Programming
Introduction to Bash Programming, part 3
CMPSC 60: Week 5 Discussion
Presentation transcript:

Chapter 9: The TC Shell Everything you thought you knew is now wrong

In this chapter … Background Accessing tcsh Startup Files Commonality with bash Standard error Variables Control structures and builtins

Background TC Shell - an expansion of the C Shell from BSD The ‘T’ comes from TENEX and TOPS-20 OSes Meant to add features such as command completion to csh Not a very good scripting language – bash is much better Most features in bash are in tcsh, just might have different syntax

Shell Scripting Caveat Recall that we can specify which shell to use for a script by starting the first line with #!/path_to_shell Without this line, tcsh will use sh to execute the script unless you run the script with tcsh explicitly Different than bash and other shells Even tcsh admits it’s not great

Accessing tcsh Easiest way is to just issue tcsh Want to change your login shell to tcsh? –chsh Exiting tcsh –exit –logout (only if login shell) –CTRL-D (if ignoreeof not set)

Startup Files Logon shell –/etc/csh.cshrc –/etc/csh.logon –~/.tcshrc or ~/.cshrc –~/.login Non-logon shell –/etc/csh.cshrc –~/.tcshrc or ~/.cshrc

More files On logout –/etc/csh.logout –~/.logout History events loaded from –~/.history

Things in common with bash Command line expansion –Called substitution in tcsh docs History –history builtin works the same –! history references work the same –Instead of HISTSIZE and HISTFILESIZE, tcsh uses history and savehist –If variable histlit is set, history shows literal commands before command line substitution

tcsh vs. bash con’t Aliases –Syntax: alias name “value” –Allows you to reference command line arguments using \!* or \!:n –Special aliases beepcmd – instead of bell cwdcmd – whenever you change directories periodic – a periodic command to run ( tperiod ) precmd – runs just before shell prompt shell – absolute path to use for scripts w/o #!

tcsh vs. bash con’t Job control –Almost identical, slightly different for multiple processes spawned at once Filename substitution –*, ?, [], {}, ~ all the same –~+, ~- not available Directory stack – same Command Substitution $() – NOT available –Use `command` instead

Standard Error tcsh doesn’t have an easy way to capture standard error like bash (i.e. 2> ) Instead we have to use >& to combine standard error and standard out So grab standard out first, then combine out and error to capture error Ex: (cat x y > results) >& errors

Word Completion Tab completion is similar in tcsh Start with an ambiguous reference then hit tab If there are multiple matches, it will maximize the length of the prefix Will *not* show a list of possible matches unless you press CTRL-D

Variables In tcsh, there are two scopes, local and global To declare a local variable, use: set variable = value –Note the spaces – different than bash To declare a local integer variable = value To declare a global (avail. to child procs): setenv variable value

Variables con’t Just like bash, use a $ to reference a variable’s contents (also ${ } ) unset, unsetenv removes variables To declare an array of strings: set variable = ( values … ) To reference single entries use [] operator (base 1) echo variable[2] set variable[4] = “Value”

Numeric Variables builtin lets you work with numeric expressions variable = ( $count + 4 ) / 5 Caveat – separate each element by a space Available operators: =, +=, -=, *=, /=, %=, +, -, *, /, %

Numeric Variables con’t To make an array of numeric variables, you actually have to use set set variable = ( ) Then to access the variable[2] = 2

More variable goodness $#variable – displays the number of elements in a variable array $?variable – displays whether the variable is set (1 for set, 0 for not set) To read user input into a variable, set the variable to “$<“ –E.g. in a script echo –n “Enter a value:” set usr_input = “$<“

Important Shell Variables autologout – set timeout period cwd – contains current working directory histfile – contains location of history history – how many history items to keep home – your home directory mail – where your mail is stored owd – previous (old) working directory

Shell Variables, con’t histlit – show literal commands in history ignoreeof – ignore CTRL-D nobeep – disables shell beeps noglob – turns of file globbing rmstar – prompt for rm * commands visiblebell – causes screen to flash for bells

Shell Variables, con’t argv – array of command line args –$n, $* –Use $#argv to get number of args

Misc bindkey Control structures