title: use expect to enter password when need sudo in script
body: <p>I am using Ubuntu 14.04 and installed expect. I am trying to write a script to enter password when it prompted.<br>
  <strong>UPDATED Code:</strong></p>
  
  <pre><code>  #!/usr/bin/expect -d
    set timeout 20
  
    set pw odroid
    spawn sudo apt-get update
  
    expect {\[sudo]\ password for odroid: }
    send "$pw\r"
  
    close
  </code></pre>
  
  <p>Any suggestions? thx</p>
  
  <p><strong>UPDATE Errors:</strong></p>
  
  <pre><code>expect: does "" (spawn_id exp4) match glob pattern "\[sudo]\ password for odroid: "? no
  [sudo] password for odroid: 
  expect: does "[sudo] password for odroid: " (spawn_id exp4) match glob pattern "\[sudo]\ password for odroid: "? yes
  expect: set expect_out(0,string) "[sudo] password for odroid: "
  expect: set expect_out(spawn_id) "exp4"
  expect: set expect_out(buffer) "[sudo] password for odroid: "
  send: sending "odroid\r" to { exp4 }
  </code></pre>