Amol Kahat Amol Kahat - 4 months ago 19
Bash Question

Expect not accepting - value

Hi I try to run expect with - values. But i'm getting bad flag error.

Test File:

echo "Enter Number:"
read num
echo $num


Expect File:

spawn sh test.sh
expect -- "Enter Number:" {send "-342345"}


I tried it with \- option still it's not working.

Answer

Try this

$ cat test.sh
echo "Enter number"
read num
echo $num

and

$ cat test.exp 
spawn sh test.sh
set value "-342345"
expect "Enter number" {
    send -- "$value\r"
}
interact

Run above command as

$ expect test.exp
Comments