2012-06-21 3 views
0

다음의 명령을 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 

다음 게시물은 grant postgres db에 쓰여 있습니다. 하지만 작동하지 않습니다.

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 

제발 도와주세요 결과 다음과 같은합니다.

+0

당신이 정교한 수 공간을 두지 않는다? 무엇을 작동하지? 예상되는 결과는 무엇입니까? _actual_ 결과는 무엇입니까? 오류 메시지? 그에 따라 질문을 편집하십시오. –

+0

http://stackoverflow.com/questions/2268104/basic-bash-script-variable-declaration-command-not-found/2268117#2268117 –

답변

4

변수와 할당 할 때 '='는 변수

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