Download
ling 408 508 programming for linguists n.
Skip this Video
Loading SlideShow in 5 Seconds..
LING 408/508: Programming for Linguists PowerPoint Presentation
Download Presentation
LING 408/508: Programming for Linguists

LING 408/508: Programming for Linguists

107 Views Download Presentation
Download Presentation

LING 408/508: Programming for Linguists

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. LING 408/508: Programming for Linguists Lecture 7 September 16th

  2. Administrivia • Homework 3 graded

  3. Here document • Pre-programmed interaction: • (here document: inline file) rm () { /bin/rm -i "$@" } export -f rm #!/bin/bash bash confirm.sh $1 <<EOF y EOF #!/bin/bash if [ $# -ne 1 ]; then echo "usage: filename" exit 1 fi touch $1 rm $1 #!/bin/bash bash confirm.sh $1 <<<y

  4. Interaction using expect • expect is a program that executes preprogrammed interaction using commands including: • expect string look for string in input • send string respond with string (/r for return) • spawn string execute a program under expect • interact gives control to user output will appear on terminal expect is written using a programming language called TCL (Tool Control Language) aka "tickle" #!/usr/bin/expect -f expect "hello" send "world\n"

  5. Interaction using expect • Knock knock joke responder: • #!/usr/bin/expect -f • expect "knock knock\n" • send "who's there?\n" • expect -re "(.*)\n" • send "$expect_out(1,string) who?\n" • expect "\n" • send "Very funny\n" • [1934 Knock knock joke from Wikipedia]

  6. Interaction using expect • expect can pattern match against regular expressions using flag –re • expect -re "(.*)\n" • matching patterns are stored in variables: • $expect_out(1,string)

  7. Interaction using expect • Let's interact with the BMI homework solution …