如何将变量从shell脚本传递到sql文件
我有一个名为test.sh的shell文件,它正在调用其他sql文件“table.sql”“table.sql”文件将创建一些表,但我想在特定的模式“bird”中创建这些表 sql文件的内容如何将变量从shell脚本传递到sql文件,sql,linux,postgresql,shell,Sql,Linux,Postgresql,Shell,我有一个名为test.sh的shell文件,它正在调用其他sql文件“table.sql”“table.sql”文件将创建一些表,但我想在特定的模式“bird”中创建这些表 sql文件的内容 create schema bird; --bird should not be hard coded it should be in variable set search_path to 'bird'; create table bird.sparrow(id int, name varchar2(20
create schema bird; --bird should not be hard coded it should be in variable
set search_path to 'bird';
create table bird.sparrow(id int, name varchar2(20));
shell文件的内容
dbname=$1
cnport=$2
schemaname=$3
filename=$4
gsql -d ${dbname} -p ${cnport} -f ${filenam} #[how to give schema name here so that it can be used in table.sql without hardcoding]
我将像这样执行我的shell文件
sh test.sh db1 9999 bird table.sql
在shell中进行比较容易,例如:
dbname=$1
cnport=$2
schemaname=$3
filename=$4
gsql -d ${dbname} -p ${cnport} <<EOF
create schema $3; --bird should not be hard coded it should be in variable
set search_path to '$3';
create table bird.sparrow(id int, name varchar2(20));
EOF
dbname=$1
cnport=$2
schemaname=$3
文件名=$4
gsql-d${dbname}-p${cnport}