Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将变量从shell脚本传递到sql文件_Sql_Linux_Postgresql_Shell - Fatal编程技术网

如何将变量从shell脚本传递到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

我有一个名为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));
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}