Skip to content

Instantly share code, notes, and snippets.

@s-kush
Forked from ksafranski/expecting.md
Created April 2, 2020 09:45
Show Gist options
  • Select an option

  • Save s-kush/6504c0fadc3faecfe01e77a4795db622 to your computer and use it in GitHub Desktop.

Select an option

Save s-kush/6504c0fadc3faecfe01e77a4795db622 to your computer and use it in GitHub Desktop.
Basic principles of using tcl-expect scripts

Setup Your Script

The first step, similar to writing a bash script, is to tell the script what it's executing under. For expect we use the following:

#!/usr/bin/expect
``

### Variables

Variables are very simple, just use `set {name} {value}`, for example:

set a "apple" set b "banana" set c "cantalope"


Referencing variables is done by simply appending `$` to the name - so `$a` would contain `apple`.


### Arguments

If you want to set a variable by passing in an argument simply use the following:

set user [lindex $argv 0] set password [lindex $argv 1]


Then, when running the script I could supply the varaible content via:

./myscript.tcl myuser mypassword


### 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment