0

Hello Stack over flowers ;-)

I am looking for equivalent of bash's command, but for expect:

VAR="ble something"

if [[ "$VAR" =~ "*something" ]]; then
  VAR2="XYZ"
else
  VAR2="YYY"
fi
echo $VAR2

# VAR2 = YYY in that case

I tried something like

if {[$VAR =~ "*3*"]}
{
set VAR2 "XYZ"
puts "$VAR2"
}
else
{
set VAR2 "YYY"
puts "$VAR2"
}

...but no luck. Thank you in advance for Your help.

Irka Irenka
  • 164
  • 10

1 Answers1

0

Expect is really an extension to the Tcl language, which means you can use string match:

if {[string match "*3*" $VAR]} {
    # It is a match, do something
} else {
    # Not a match
}

The string match command returns 1 if it matches, and 0 if it does not. Note that string match behaves like wildcard match, not regular expression match.

Hai Vu
  • 37,849
  • 11
  • 66
  • 93