1. #!/bin/bash  
  2. content= 'Line'  
  3. expect <<EOF  
  4. set  file  "hello.txt"  
  5. set  fd [ open  \$ file  r]  
  6. set  n 0  
  7. while  {[gets \$fd line] != -1} {  
  8.          incr n  
  9.          puts  "$content\$n: \$line"  
  10. }  
  11. close \$fd  
  12. EOF


1.

#!/usr/bin/expect -f
set  fd [ open  /etc/passwd  r]
set  data [ read  $fd]
puts $data  ### 这样就可以输出每一行
close $fd