- 此问题在此处已有答案**:
Pass commands as input to another command (su, ssh, sh, etc)(3个答案)
22小时前关门了。
我有以下代码在我的bash脚本安装golang和psql服务器,我想创建一个用户名为"admin"和密码为"admin"的用户。运行脚本后,它将进入psql服务器,但psql -c "CREATE USER admin WITH PASSWORD 'admin';"
没有得到执行。
#!/bin/bash
# Install golang
echo "Installing required package"
sudo apt-get update
sudo apt install snapd
snap install go --classic
# Install postgreSQL
echo "Installing postgreSQL"
sudo apt-get update
sudo apt install postgresql postgresql-contrib postgresql-client
# Starting database
echo "Starting Database"
sudo service postgresql start
sudo -u postgres psql
# Creating user "admin" with password "admin"
echo "Creating user 'admin' with password 'admin'"
psql -c "CREATE USER admin WITH PASSWORD 'admin';"
2条答案
按热度按时间wfveoks01#
我通过删除
sudo -u postgres psql
并使用sudo -u postgres psql -c "CREATE USER admin WITH PASSWORD 'admin';"
修复了该问题,现在运行良好z9ju0rcb2#
echo "正在启动数据库" sudo服务postgresql启动
完成此步骤后。(只需切换到postgres)
苏波斯特格雷
psql-c "使用密码" admin "创建用户管理员; "