tags:

views:

32

answers:

2

On page 35, in the book "Exploring Expect", it says "The return command can be used to make a source command return. Otherwise, source returns only after executing the last command in the file."

I don't quite understand what it's getting at. I'd like to know what this means and how this is useful.

Thank you.

A: 

Basically, when the 'return' command is encountered, 'expect' will stop processing the script further, and return to the parent script (if any) that ran it using the 'source' command. It's much like 'return' in any programming language.

Gintautas Miliauskas
So when would I use this feature in a a file I'm using as a source? For example I may want to only load the first 5 functions of a file I've defined 10 functions in. So I will put a return after the 5th function? That scenario just doesn't make sense to me...
Derek Litz
@Derek Litz - for example you could put linux-specific code at the bottom of a file and put "if we're not on linux, return" just before it so that the code is not executed unless we're on linux.
joefis
+1  A: 

an example:

main script:

puts "about to source external file"
set some_var true
source something.exp
puts "done sourcing"

something.exp

puts "in something.exp"
if {$some_var} return
puts "you won't see this if some_var is true"
glenn jackman