620: UNIX --- Lecture 6

Variable Modifiers

One colon modifiers for variable substitutions, e.g.,
:h removes a trailing pathname component, leaving the head
:t removes all leading pathname components, leaving the tail
:r removes an extension .xxx component, leaving the root name
:e removes the root name, leaving the extension

For more modifiers see pages 201-202.

Special Substitutions

$?var (or ${?var}

substitutes the string 1 if var is set; otherwise 0, e.g.,

?editor

will have value 1 if variable editor is set; otherwise it will have value 0.

Input and Output

echo -n

Option -n prevents the NEWLINE from being displayed.

Metavariable

$<

allows input to be entered by user, e.g.,

enter

The Here Document

General form is:

command <<word
zero or more lines of input included here
word

Sample applications:

  • phonenumber
  • timestamp

    Sample Useful Csh Scripts

  • Lists directory files
  • Clean directory
  • Conditional copy
  • Total bytes in directory hierarchy - recursive script
  • Script for grading hw1