0
votes

Below is my sample expect script.

#!/usr/bin/expect

set pem [lindex $argv 2]
puts -nonewline "do you want to take histogram\r"
flush stdout
gets stdin pem
if { $pem == "y" } {
    send "./statsCollector.sh\r"
} else {
    puts "aborting\r"
}
expect " bin\]\$ "

I need user prompt like yes,Y or y to run the my script (i.e. statsCollector.sh). If user inputs anything other like this then "aborting" should be message on window.

Here user input is not working properly, also after the aborting it hangs with that same message. Please correct me if I'm doing wrong here.

1
is this your full script? or just part of it? - pynexj
no it is just part of my script - Vijay Patil

1 Answers

0
votes

I'd use this:

if {[string match {y*} [string tolower [string trimleft $pem]]]} {...

Removing leading whitespace, if the first character is "y" case insensitively, then ... do stuff

ref: https://tcl.tk/man/tcl8.6/TclCmd/string.htm