Linux Shell脚本-在循环中使用变量

Linux Shell脚本-在循环中使用变量,linux,postgresql,shell,Linux,Postgresql,Shell,我使用以下命令授予postgres db。它正在工作 for tbl in `psql -qAt -c "select sequence_name from information_schema.sequences where sequence_schema = 'public';" performanceeyedev` ; do psql -c "alter table $tbl owner to prodteam" performanceeyedev ; done DB = 'perfo

我使用以下命令授予postgres db。它正在工作

for tbl in `psql -qAt -c "select sequence_name from information_schema.sequences where sequence_schema = 'public';" performanceeyedev` ; do  psql -c "alter table $tbl owner to prodteam" performanceeyedev ; done
DB = 'performanceeyedev';
OWNER = 'prodteam';

for tbl in `psql -qAt -c "select sequence_name from information_schema.sequences where sequence_schema = 'public';" $DB` ;
do  psql -c "alter table $tbl owner to $OWNER" $DB ; done

for tbl in `psql -qAt -c "select table_name from information_schema.views where table_schema = 'public';" $DB` ;
do  psql -c "alter seq $tbl owner to $OWNER" $DB ; done
我为grant postgres db编写以下脚本。但它不起作用

for tbl in `psql -qAt -c "select sequence_name from information_schema.sequences where sequence_schema = 'public';" performanceeyedev` ; do  psql -c "alter table $tbl owner to prodteam" performanceeyedev ; done
DB = 'performanceeyedev';
OWNER = 'prodteam';

for tbl in `psql -qAt -c "select sequence_name from information_schema.sequences where sequence_schema = 'public';" $DB` ;
do  psql -c "alter table $tbl owner to $OWNER" $DB ; done

for tbl in `psql -qAt -c "select table_name from information_schema.views where table_schema = 'public';" $DB` ;
do  psql -c "alter seq $tbl owner to $OWNER" $DB ; done
结果如下

./grant.sh: line 1: DB: command not found
./grant.sh: line 2: OWNER: command not found
ERROR:  syntax error at end of input
LINE 1: alter table dir_destinations_dir_dest_id_seq owner to 
                                                              ^
ERROR:  syntax error at end of input
LINE 1: alter table dir_types_dir_type_id_seq owner to 
                                                       ^
ERROR:  syntax error at end of input
LINE 1: alter table dir_specialities_dir_sp_id_seq owner to 
                                                            ^
ERROR:  syntax error at end of input
LINE 1: alter table lb_report_types_id_seq owner to 
                                                    ^
ERROR:  syntax error at end of input
LINE 1: alter table too_many_submission_summary_id_seq owner to 
                                                                ^
ERROR:  syntax error at end of input
LINE 1: alter table web_campaigns_web_camp_id_seq owner to

请帮帮我

分配变量时,不要在变量和“=”之间留空格

DB='performanceeyedev';
OWNER='prodteam';

分配变量时,不要在变量和“=”之间留空格

DB='performanceeyedev';
OWNER='prodteam';

你能详细说明一下吗?什么不起作用?预期的结果是什么?实际结果如何?错误消息?请相应地编辑您的问题。您能详细说明一下吗?什么不起作用?预期的结果是什么?实际结果如何?错误消息?请相应地编辑您的问题。