80 likes | 210 Views
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.
E N D
LING 408/508: Programming for Linguists Lecture 7 September 16th
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 #!/bin/bash if [ $# -ne 1 ]; then echo "usage: filename" exit 1 fi touch $1 rm $1 #!/bin/bash bash confirm.sh $1 <<<y
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"
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]
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)
Interaction using expect • Let's interact with the BMI homework solution …