1 / 7

LING 408/508: Programming for Linguists

LING 408/508: Programming for Linguists. Lecture 7 September 16 th. Administrivia. Homework 3 graded. 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.

roy
Télécharger la présentation

LING 408/508: Programming for Linguists

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

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 …

More Related