0

How can I do line breaks properly in bash script? The following command works fine without adding line breaks:

for i in {table1,table2,table3}; do psql -U postgres -c "\COPY (SELECT * FROM "DB"."$i") TO "$i".csv DELIMITER ',' CSV"; done

However, I would like add to more table names in the script. I keep getting (Filename too long) error. I would like to do something like the following:

    for i in {table1, \
     table2, \
     table3}; do psql -U postgres -c "\COPY (SELECT * FROM "DB"."$i") TO "$i".csv 
     DELIMITER ',' CSV"; done

But I keep getting the error:

ERROR:  syntax error at or near "}" 
1
  • 2
    Remove the {, }, and ,s between braces. Commented Dec 1, 2021 at 21:22

1 Answer 1

2

You don't need curly braces {} to denote an array in bash, just do it like:

for i in table1 \
     table2 \
     table3; do psql -U postgres -c "\COPY (SELECT * FROM "DB"."$i") TO "$i".csv 
     DELIMITER ',' CSV"; done
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.