I have the following code in a function. Is there a way to get the exit code after the expect script is run, however do a command with the exit code within the same function? I know you can you "$?" after the function is executed, however I would like to handle the exit code accordingly within the function itself.
getVersion(){
cmd="command_with_options"
mcasPassword="sample"
expect <<-EOS |& tee ${hostname}.log
#!/usr/bin/expect
set timeout $EXP_TIMEOUT
spawn sh
expect "$prompt"
send -- "$cmd\r"
expect "*assword"
send -- "$mcasPassword\r"
expect {
"*rror*" {
puts "\nAn issue was faced\n"
exit 1
}
"$prompt" {
puts "\nSuccessfully reached\n"
}
}
expect eof
exit 0
EOS
echo "Error code is as follows: $?"
#The above line isn't capturing the exit code ^
}
Any help would be highly appreciated.