what does this statement mean for expect or for bash? -


exploring expect page 219 :

#!/bin/bash set kludge { ${1+"$@"} shift shift exec expect -f $0 ${1+"$@"} } # rest of script follows 

i able execute expect script within bash interpreter,even can pass command line arguments like: ./scriptname arg1 arg2 arg3 , on when tried sh -x ./scriptname arg1 arg2 arg3 threw error. please clarify above statements , put expect scripts inside bash

looking @ expect first, it's pretty simple. set command, when given 2 arguments, sets value of variable. here, variable name kludge , value multi-line string between {braces}. note in tcl (and expect) braces suppress expansion (variable substitution, command expansion, etc), in same way single quotes act in shell. assuming variable kludge never used, innocuous statement.

a bit trickier shell. shell's set command in context set positional parameters. after command:

$1 = "kludge" $2 = "{" $3, $4, ... <= original command line parameters 

then there 2 shift commands pop "kludge" , "{" off "stack" of parameters, restoring original positional parameters. exec command launch expect, replacing running shell process. if exec not used, expect run , (presumably) terminate, , shell report syntax error on next line: }

overall, overly clever way launch expect program. replace before "# rest of script follows" with

#!/usr/bin/expect -f 

or if there's much more stuff happening in shell portion, use this:

#!/bin/bash whatever shell initialization required expect -c << 'end_of_expect' # rest of expect script follows # ... end_of_expect 

to pass options in case:

expect - "$@" << 'end_of_expect' # ... 

the single - tells expect commands come on stdin.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -