Search code examples
expect

How to get the home directory from a variable in expect?


I'd like to set the home directory as a variable.

How can I do that?

This is my code:

set fp [open "$HOME/temp.sh" r]
set data [read $fp]
close $fp
set ::logfile [open "$HOME/log.sh" a]

Solution

  • Since Expect is an extension of Tcl, you use Tcl's env array:

    set fp [open "$::env(HOME)/temp.sh" r]
    set data [read $fp]
    close $fp
    set ::logfile [open "$::env(HOME)/log.sh" a]
    

    See http://tcl.tk/man/tcl8.5/TclCmd/tclvars.htm and the Tcl tutorial.