回答:
文書化され、あなたは経由のメタコマンドを実行することができます--commandオプション。
sudo -u postgres psql --command '\password postgres'
単一引用符は、シェルがバックスラッシュをエスケープ文字として扱わないようにします。
sudo -u postgres psql --command "\password"。私の質問がなぜ投票されたのか疑問に思う。
"\\..."。
The backslash retains its special meaning only when followed by one of the following characters: ‘$’, ‘`’, ‘"’, ‘\’, or newline.私はそれが"\password"うまくいった理由だと思う。
\passwordインタラクティブなターミナルが必要なpsql コマンドを使用する代わりに、次を使用できます。
ALTER USER postgres WITH PASSWORD 'newpassword';
経て、言うpsql -cコマンド:
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'newpassword';"
man。man psql今後もお試しください。