How to pass password on stdin to psql and other utilities?

postgresql

Solution

You could set an environment variable PGPASSWORD.

Problem

One can accomplish passing the password by specifying in ~/.pgpass. I am however curious if there is a way to do so with stdin without using something like `expect`. The following does not appear to work: ``` psql -U postgres <<< "mypw" ```

Original source