1 © 2012 John Urrutia. All rights reserved. Chapter 09 The TC Shell.

Slides:



Advertisements
Similar presentations
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Advertisements

Chapter 9: The TC Shell Everything you thought you knew is now wrong.
1 © 2001 John Urrutia. All rights reserved. Chapter 5 The Shell Overview.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Linux+ Guide to Linux Certification, Second Edition
Shell Basics CS465 - Unix. Shell Basics Shells provide: –Command interpretation –Multiple commands on a single line –Expansion of wildcard filenames –Redirection.
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
2000 Copyrigths Danielle S. Lahmani UNIX Tools G , Fall 2000 Danielle S. Lahmani Lecture 3.
23-Jun-15Advanced Programming Spring 2002 bash Henning Schulzrinne Department of Computer Science Columbia University.
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
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).
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
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.
Introduction to Shell Script Programming
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.
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
Chapter 6: Shell Programming
An Introduction to Unix Shell Scripting
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 8 Shell.
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.
Shells. A program that is an interface between a user at a terminal and the computers resouces ▫The terminal may be real or an emulator The shell is.
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.
Writing C-shell scripts #!/bin/csh # Author: Ken Berman # Date: # Purpose: display command and parameters echo $0 echo $argv[*]
1 UNIX essentials (hands-on) the directory tree running programs the shell → command line processing → special characters → command types → shell variables.
LINUX System : Lecture 6 Shell Programming
Linux+ Guide to Linux Certification, Third Edition
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
Shell Programming. 222 Lecture Overview  Shell variables  Shell scripts  Control flow and Boolean operators  Shell programming tips  Shell programming.
Workbook 6 – Part 2 The Bash Shell
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
CSC 352– Unix Programming, Spring 2015 March 2015 Shell Programming (Highlights only)
1 © 2001 John Urrutia. All rights reserved. Chapter 10 using the Bourne Again Shell.
Lesson 2 1.Commands 2.Filename Substitution 3.I/O Redirection 4.Command Grouping 5.Shell Responisibilites Review of the Basics.
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.
UNIX shell environments CS 2204 Class meeting 6 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
1 © 2000 John Urrutia. All rights reserved. Session 5 The Bourne Shell.
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.
1 Unix/Linux commands and shell programming-Part 2 (Dr. Mohamed El Bachir Menai)
CSCI 330 UNIX and Network Programming Unit III Shell, Part 1.
Agenda The Bourne Shell – Part II Special Characters Ambiguous File Reference Variable Names and Values User Created Variables Read-only Variables (Positional.
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.
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.
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.
Introduction to the bash Shell (Bourne-Again SHell)
Introduction to Shells
Shell Features CSCI N321 – System and Network Administration
The UNIX Shell Learning Objectives:
CSC 352– Unix Programming, Fall 2012
Shell Environments.
CSE 303 Concepts and Tools for Software Development
Shell Programming.
Linux Shell Script Programming
CSC 352– Unix Programming, Fall, 2011
Chapter 3 The UNIX Shells
Introduction to Bash Programming, part 3
Presentation transcript:

1 © 2012 John Urrutia. All rights reserved. Chapter 09 The TC Shell

2 © 2012 John Urrutia. All rights reserved. Topics Background Shell Scripts Entering and Leaving The TC shell  Startup files

3 © 2012 John Urrutia. All rights reserved. Background Originally developed at Berkeley.  csh – C shell  tcsh – Like bash, incorporates the best of other C shells.  tcsh and bash are very similar… However

4 © 2012 John Urrutia. All rights reserved. Background tcsh – ignores spaces in assignment but bash will give you an error  set myvar = value (OK in tcsh)  set myvar=value (OK in bash) Referencing an unset variable creates an error in tcsh but not in bash

5 © 2012 John Urrutia. All rights reserved. Shell Scripts Shell scripts are run implicitly by the shell designated in the first line. Scripts can be run by other shells if they are explicitly invoked.  tcsh myscript #!/bin/bash (this is ignored)

6 © 2012 John Urrutia. All rights reserved. Entering The TC shell To enter the tcsh from the command line  tcsh If you want tcsh or any other shell set as your permanent shell use  chsh

7 © 2012 John Urrutia. All rights reserved. Leaving the tcsh Shell The ignoreeof variable effects the exit  If set CONTROL-D will issue a prompt on how to exit  The exit command will always work  logout will exit only from the login shell

8 © 2012 John Urrutia. All rights reserved. The tcsh startup files On entry to tcsh executes  /etc/csh.cshrc  Sets prompt and file creation permissions  /etc/csh.login  Sets the PATH, HOSTNAME  Sets the delete key  Sets the user profile and executes scripts

9 © 2012 John Urrutia. All rights reserved. The tcsh startup files.tcshrc or.cshrc  Establishes local shell variables  Executes for each new shell Only if tcsh is your login shell .history  Re-builds the history buffer

10 © 2012 John Urrutia. All rights reserved. Only if tcsh is your login shell .history  Re-builds the history buffer .login  Executes once at the begining of a session  Used to set environmental variables, mail, terminal, etc. The tcsh startup files

11 © 2012 John Urrutia. All rights reserved. Only if tcsh is your login shell .chdir  Re-builds the directory stack buffer .logout  Performs termination processes at exit The tcsh startup files

12 © 2012 John Urrutia. All rights reserved. Topics Common bash and tc shell features  History  Alias  Job control  Filename Substitution  Directory Stack Manipulation

13 © 2012 John Urrutia. All rights reserved. Common bash and tc features History  Event control works the same but has additional event modifiers  u, l, a  u – First lowercase letter set to upper case  l – First uppercase letter set to lower case  a – Apply globally to command line

14 © 2012 John Urrutia. All rights reserved. Common bash and tc features History  set history=10  Sets the number of commands to store  set savehist=5  Sets the number of commands to save across sessions  set histlit  When set displays literal history without command line expansion.

15 © 2012 John Urrutia. All rights reserved. Common bash and tc features Alias works the same but has syntax differences.  bash  alias ls=”ls –lf”  tcsh  alias ls ls –lf  Special tcsh aliases

16 © 2012 John Urrutia. All rights reserved. Common bash and tc features Special tcsh aliases  beepcmd  Replaces that annoying beep!  cwdcmd  Executes when you change the working directory  periodic  Executes after a specified number of minutes

17 © 2012 John Urrutia. All rights reserved. Common bash and tc features Special tcsh aliases  precmd  Executes just before shell displays prompt  shell  Name of shell to process scripts without #!

18 © 2012 John Urrutia. All rights reserved. Common bash and tc features Job Control  Is very similar to bash  tcsh will display all process id’s used by a background job whereas bash displays only the last one.

19 © 2012 John Urrutia. All rights reserved. Common bash and tc features Filename Substitution  Uses the same wildcards  ? * [ ]  Setting the noglob variables suppresses all filename substitution Directory stack manipulation  Works the same way as bash

20 © 2012 John Urrutia. All rights reserved. Topics Redirecting Standard Error Word Completion  Filename Completion  Tilde Completion  Command and Variable Completion Command-line Editing Spelling Correction

21 © 2012 John Urrutia. All rights reserved. Redirecting standard error tcsh combines both stdout and stderr through the use of the >& symbols tcsh does not provide a simple way of redirecting just the error output but a good work around follows.

22 © 2012 John Urrutia. All rights reserved. Redirecting standard error …]$ cat x cat: No such file or directory …]$ cat y This is what’s in y. …]$ (cat x y > stdfile) >& errfile …]$ cat stdfile This is what’s in y. …]$ cat errfile cat: No such file or directory

23 © 2012 John Urrutia. All rights reserved. Topics Redirecting Standard Error Word Completion  Filename Completion  Tilde Completion  Command and Variable Completion Spelling Correction

24 © 2012 John Urrutia. All rights reserved. Word Completion The process that tcsh uses to complete filenames, commands, and variable names.

25 © 2012 John Urrutia. All rights reserved. Filename Completion Any filename argument will be completed by pressing the tab key.  If the argument is unique it is replaced  If not a short beep is heard. If the filename is not unique  You may continue to type until it is.  Pressing Ctrl-D  This displays all matching filenames

26 © 2012 John Urrutia. All rights reserved. Tilde Completion If the first character is a ~ the shell attempts to expand it to a user name when you enter a tab. If a directory by the username exists a / is appended. …]$ cd ~fe (tab) …]$ cd ~fester/ …]$ pwd /home/fester  tab causes expansion

27 © 2012 John Urrutia. All rights reserved. Command and Variable Completion Works the same way as filename completion It searches the $PATH variable for command names. The context of the ambiguous element determines if it is a command or variable

28 © 2012 John Urrutia. All rights reserved. Topics Redirecting Standard Error Word Completion  Filename Completion  Tilde Completion  Command and Variable Completion Spelling Correction

29 © 2012 John Urrutia. All rights reserved. Spelling Correction tcsh will attempt to correct spelling errors in commands  You must set the correct shell variable  cmd – correct only the command  all – correct the entire command line  complete – correct like filename completion  Use META-s to correct command  Use META-$ to correct the line

30 © 2012 John Urrutia. All rights reserved. Topics Variables  Variable substitution  String variables  Arrays of String variables  Numeric variables  Shell variables Expressions

31 © 2012 John Urrutia. All rights reserved. Variables tcsh stores all variables as strings Variable names are limited to 30 chr.  Must be from A – Z, a – z, 0 – 9, or _  Cannot start with a numeral

32 © 2012 John Urrutia. All rights reserved. Variables Three builtins to declare display, & assign variable values set – declares local - declares local numeric variables setenv – declares environmental variables (similar to using export)

33 © 2012 John Urrutia. All rights reserved. Variable substitution $ - used to identify variables \$ - no substitution show $ “ – substitution will always occur ‘ – substitution will never occur

34 © 2012 John Urrutia. All rights reserved. String Variables tcsh uses explicit declaration …]$ set name = fred …]$ echo $name fred …]$ name = george name: Command not found.

35 © 2012 John Urrutia. All rights reserved. Arrays of String Variables An array is a set of elements that can be accessed individually. You must declare the array before you use it. The actual number of elements are fixed at declaration …~]$ set colors = ( a b c d )

36 © 2012 John Urrutia. All rights reserved. Arrays of String Variables To reference the entire array use just the name …~]$ echo $colors a b c d To reference individual elements use the name and […] …~]$ echo $colors[2] b

37 © 2012 John Urrutia. All rights reserved. Arrays of String Variables To reference a range of elements use the variable name and [ n1-n2 ] …~]$ echo $colors[2-3] b c

38 © 2012 John Urrutia. All rights reserved. Numeric Variables builtin will assign values to numeric variables. You can perform arithmetic operations on numeric variables by using the C++ operators  =, +=, -=, *=, /=, %= mynum += 10

39 © 2012 John Urrutia. All rights reserved. Array of Numeric Variables You must use the set builtin to declare a numeric array before you use to assign array values. …~]$ set ages=( ) ages[2]=15 ages[3]=($ages[2] + 4) …~]$ echo $ages[3] 19

40 © 2012 John Urrutia. All rights reserved. Special Variable Forms The number of elements in an array  $# variable-name Returns 1 if variable is set or 0 it isn’t  $? variable-name Reading user input using set  set input_line = “$<“  Set input_word = $< (space delimited)

41 © 2012 John Urrutia. All rights reserved. Topics Control Structures Interrupt handling Built-ins

42 © 2012 John Urrutia. All rights reserved. Control Structure Differences if ( expression ) simple-command  if ( $#argv == 0 ) echo “No Arguments” No Arguments  if ( -d MyDir ) echo “ This is a directory” This is a directory  if ( -d MyDir ) filetest –A: MyDir Wed Nov 14 04:03:

43 © 2012 John Urrutia. All rights reserved. Control Structure Differences Label : – Labels are identifiers that act as branch points in a script. goto Label : – Transfers control directly to the label onintr Label : – Transfers control directly to the label when interrupt key is pressed

44 © 2012 John Urrutia. All rights reserved. if … then … endif If ( expression ) then command endif

45 © 2012 John Urrutia. All rights reserved. If ( expression ) then command else command endif if … then … else … endif

46 © 2012 John Urrutia. All rights reserved. if ( expression ) then command else if ( expression ) then command else command endif if … then … else if … endif

47 © 2012 John Urrutia. All rights reserved. foreach loop-index ( argument-list ) command end Substitutes the argument-list in order to the loop-index  foreach x (1 a 2 b 3 c) echo $x end foreach … end

48 © 2012 John Urrutia. All rights reserved. while … end while ( expression ) exec if expression command is true end tcsh does not support until.

49 © 2012 John Urrutia. All rights reserved. switch … case … endsw switch ( test-string ) case pattern : commands breaksw default: commands endsw

50 © 2012 John Urrutia. All rights reserved. Topics Control Structures Interrupt handling Built-ins

51 © 2012 John Urrutia. All rights reserved. Builtins Tcsh provides a set of “internal” utilities called builtins.  Builtins run under the same PID as the shell  The builtins command will display all tcsh builtin commands

52 © 2012 John Urrutia. All rights reserved. The tcsh Builtins bindkeybreakbreakswbuiltinscase cdchdircompletecontinuedefault dirsecho echotc elseend endifendswevalexecexit fgfiletestforeach glob goto hashstathistoryhupifjobs killlimitlogloginlogout ls-fnicenohupnotifyonintr popdprintenvpushdrehash repeat sched setsetenvsettcsetty shift source stop suspend switch telltctimeumaskunalias uncompleteunhashunlimitunsetunsetenv waitwherewhichwhile