title: bash setsid & read freezes
body: <p>I have script for ssh login without expect:</p>
  
  <pre><code>function do_auth_connect(){
      if [ -n "$SSH_ASKPASS_TMPFILE" ]; then
          cat "$SSH_ASKPASS_TMPFILE"
          exit 0
      elif [ $# -lt 1 ]; then
          echo "Usage: echo password | $0 &lt;ssh command line options&gt;" &gt;&amp;2
          exit 1
      fi
  
      sighandler() {
          rm "$TMP_PWD"
      }
  
      TMP_PWD=$(mktemp)
      chmod 600 "$TMP_PWD"
      trap 'sighandler' SIGHUP SIGINT SIGQUIT SIGABRT SIGKILL SIGALRM SIGTERM
  
      export SSH_ASKPASS=$0
      export SSH_ASKPASS_TMPFILE=$TMP_PWD
  
      [ "$DISPLAY" ] || export DISPLAY=dummydisplay:0
      read password
      echo $password &gt;&gt; "$TMP_PWD"
  
      # use setsid to detach from tty
      #exec setsid "$@"
      setsid "$@"
  
      rm "$TMP_PWD"
  }
  </code></pre>
  
  <p>If I use command like:</p>
  
  <pre><code>echo "my_password" | do_auth_connect ssh use@domain "uname -a"
  </code></pre>
  
  <p>all work fine. But if I use:</p>
  
  <pre><code>read password
  echo "$password" | do_auth_connect ssh use@domain "uname -a"
  </code></pre>
  
  <p>script freezes.</p>
  
  <p>"set -x" shows that the script goes into a loop, and wait another "read" param.</p>
  
  <p>How I can fix this? Thanks</p>
  
  <p><strong>---UPD---</strong> (for @Barmar)</p>
  
  <p>set -x output when ok (with scp example):</p>
  
  <pre><code>+ echo 'user_password'
  + do_auth_connect scp -P 444 user@domain:/home/user/dbg.log /home/user/dbg.log
  + '[' -n '' ']'
  + '[' 5 -lt 1 ']'
  ++ mktemp
  + TMP_PWD=/tmp/tmp.X8TKTIchq6
  + chmod 600 /tmp/tmp.X8TKTIchq6
  + trap sighandler SIGHUP SIGINT SIGQUIT SIGABRT SIGKILL SIGALRM SIGTERM
  + export SSH_ASKPASS=./1.sh
  + SSH_ASKPASS=./1.sh
  + export SSH_ASKPASS_TMPFILE=/tmp/tmp.X8TKTIchq6
  + SSH_ASKPASS_TMPFILE=/tmp/tmp.X8TKTIchq6
  + '[' :0.0 ']'
  + read password
  + echo 'user_password'
  + setsid scp -P 444 user@domain:/home/user/dbg.log /home/user/dbg.log
  + echo 'user_password'
  + do_auth_connect scp -P 444 user@domain:/home/user/dbg.log /home/user/dbg.log
  + '[' -n /tmp/tmp.X8TKTIchq6 ']'
  + cat /tmp/tmp.X8TKTIchq6
  + exit 0
  + rm /tmp/tmp.X8TKTIchq6
  + exit
  </code></pre>
  
  <p>and when fails:</p>
  
  <pre><code>+ read pass
  &gt; user_password
  + echo 'user_password'
  + do_auth_connect scp -P 444 user@domain:/home/user/dbg.log /home/user/dbg.log
  + '[' -n '' ']'
  + '[' 5 -lt 1 ']'
  ++ mktemp
  + TMP_PWD=/tmp/tmp.7usdmtHgqt
  + chmod 600 /tmp/tmp.7usdmtHgqt
  + trap sighandler SIGHUP SIGINT SIGQUIT SIGABRT SIGKILL SIGALRM SIGTERM
  + export SSH_ASKPASS=./1.sh
  + SSH_ASKPASS=./1.sh
  + export SSH_ASKPASS_TMPFILE=/tmp/tmp.7usdmtHgqt
  + SSH_ASKPASS_TMPFILE=/tmp/tmp.7usdmtHgqt
  + '[' :0.0 ']'
  + read password
  + echo 'user_password'
  + setsid scp -P 444 user@domain:/home/user/dbg.log /home/user/dbg.log
  + read -p '&gt; ' pass
  </code></pre>
  
  <p>and this is all, ^C does not work :)</p>
  
  <p><strong>---UPD2---</strong></p>
  
  <p>I found out that any "read" breaks the script
  For example:</p>
  
  <pre><code>read null
  echo "user_password" | do_auth_connect scp -P 444 user@domain:/home/user/dbg.log ~/dbg.log
  </code></pre>
  
  <p>have some troubles with freezes</p>