Method1: Using -c option
#!/bin/sh
dbname="mydb"
dbuser="postgres"
table1="test1"
table2="test2"
psql -U ${dbuser} -d ${dbname} -c "
DROP TABLE ${table1};"
psql -U ${dbuser} -d ${dbname} -c "
DROP TABLE ${table2};"
psql -U ${dbuser} -d ${dbname} -c "
CREATE TABLE ${table1} \
(id int, \
name text);"
psql -U ${dbuser} -d ${dbname} -c "
CREATE TABLE ${table2} \
(id int, \
name text);"
Method2: Using EOF operator
#!/bin/sh
dbname="mydb"
dbuser="postgres"
table1="test1"
table2="test2"
psql -d ${dbname} -U ${dbuser} << EOF
DROP TABLE ${table1};
DROP TABLE ${table2};
CREATE TABLE ${table1}
(id int,
name text);
CREATE TABLE ${table2}
(id int,
name text);
EOF
No comments:
Post a Comment