Lecture 10 Shells - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Lecture 10 Shells

Description:

September 15, 2005. CSCE 510 Systems Programming. 2. CSCE 510 Fall 2005. Last Time ... History: !n, !!, !str, !!str:n, substitution. History array of pts to ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 13
Provided by: mantonm5
Category:
Tags: lecture | shells

less

Transcript and Presenter's Notes

Title: Lecture 10 Shells


1
Lecture 10Shells
CSCE 510 Systems Programming
  • Topics
  • Shell operations
  • Shell implementation
  • Redirecting I/O

September 15, 2005
2
  • Last Time
  • Exec Family examples
  • execExamples.c // (in /class/csce510-001/web/Exam
    ples)
  • Shells
  • sh, csh, bash
  • Csh features
  • Shell variables
  • Alias substitutions
  • History !n, !!, !str, !!strn, substitution
  • History array of pts to link lists
  • Filename expansion e.g., ls .c
  • Today
  • Filename expansion implementation re_comp,
    re_exec
  • Program 2

3
cshell substitutions
  • Read in the command into linked list or words

4
Regular expressions
  • Shells bash and csh dont really do real regular
    expressions. Why not?
  • Shell patterns
  • - matches any string e.g. ls a.c
  • . matches any single character e.g. ls \.c
  • str matches single character from str e.g.
    ls abc\.c
  • ? makes the previous pattern optional
  • Vi and grep use real regular expressions
  • means Kleene closure (CSCE 355) ab means
  • Functions for real regular Expressions
  • Regcomp (build NFA/DFA), regexec (Match using the
    FA)
  • man s 7 regexec

5
Filename Expansion Implementation
  • int match(const char string, char pattern)
  • int status
  • regex_t re
  • if (regcomp(re, pattern, REG_EXTENDEDREG_NOSUB)
    ! 0)
  • return(0) / report error /
  • status regexec(re, string, (size_t) 0, NULL,
    0)
  • regfree(re)
  • if (status ! 0) return(0) / report error /
  • return(1)

6
Regex regular expressions
  • several branches match one a bb
    c
  • concatenation match all in sequence abc
  • atom possibly followed by a single
  • ?
  • A bound e.g. x3,5 meaning from 3 to 5 xs
  • A bracket expression abxyz meaning 0-7
    meaning
  • Parentheses for grouping

7
cshell command substitution
  • cmd is replaced by the output of the command
  • We will describe how to do this when we talk
    about the

8
cshell filename completion
  • TAB indicates try to extend (or complete) this
    filename
  • aresgt gcc execEltTABgt // extends to gcc
    execExamples
  • aresgt gcc execEltTABgt // Shows you the choices

9
cshell command completion
  • Same but for first word and the interpretation is
    different
  • aresgt gcltTABgtltTABgt
  • gcc gccbug
    gconf-merge-tree gcov
  • gcc-3.3.6 gccmakedep gconftool-2
  • aresgt gc

10
Program 2
11
(No Transcript)
12
Shell Implementation
  • write prompt
  • read command line
  • parse into linked list of words
  • perform substitutions
  • remap Standard IO
  • build argv
  • fork/exec
Write a Comment
User Comments (0)
About PowerShow.com