Invalid Command Name

I have telnet to a machine and executed some commands in it.
pls see below :

#!/usr/bin/expect

spawn telnet 170.10.11.1 2100
  expect "login:"  
  send username\r
  expect "password:"
  send password\r
  expect "$"  
  send "touch filetest\r"
  expect "$"  
  send exit\r
  expect eof

But after this, I am executing some shell commands "echo". it throws

invalid command name "echo"
    while executing

Can anyone help me out in this case?

It's because expect doesn't understand shell commands, and you can't just mix an match them as you like within the same script.

By using expect in the shebang, you use expect as interpreter of your commands. It seems echo is no valid command for expect.

when you are using expect, echo is not a valid command. If you are going to use other commands not recognizable by expect, you might need to use 2 scripts one calling your expect script. I'm not an expert on expect but the workaround we had to go around this issue it to use 2-3 scripts.