0

I have a simple question, but I can't find an answer )

I have following script:

sqsh -S SyBaseServer -U sybuser -P mypass -C 'select top 10000 * from dba.sybtable; -mbcp' | \
awk '{print substr($0, 0, length($0)-1)}' | \
psql -1 postgresql://admin:adminpass@pgserv:5432/pgbase -f sybtopg.sql

How can I add EOF after last string of ouput of awk? I must close STDIN for psql.

Thanks!

PS The reason of fail isn't lack of EOF. It's right pipeline:

sqsh -S SyBaseServer -U sybuser -P mypass -C 'select top 10000 * from dba.wybtable; -mbcp' \
| awk '{print substr($0, 0, length($0)-1)}' | \
/psql  postgresql://admin:adminpass@pgserv:5432/pgbase -c "DELETE FROM testtable; COPY testtable FROM STDIN DELIMITER '|' CSV"
MT0
  • 143,790
  • 11
  • 59
  • 117
Dimaf
  • 653
  • 1
  • 11
  • 25
  • Possible duplicate of [how does \` cat << EOF\` work in bash?](http://stackoverflow.com/questions/2500436/how-does-cat-eof-work-in-bash) – t0mm13b Nov 05 '15 at 22:18
  • `awk` will write EOF when it reads EOF from its input. – Barmar Nov 05 '15 at 22:55
  • @t0mm13b How is this related? There's no here-doc in this question. – Barmar Nov 05 '15 at 22:56
  • IIUC the reader of a pipe should receive EOF when the (last) writing descriptor is closed, i.e. here when awk ends. Does awk linger for some reason (e.g. because sqsh does not finish and awk's input is still open)? Check with ps from another terminal. – Peter - Reinstate Monica Nov 05 '15 at 23:00

1 Answers1

1

You don't need to do anything special. When awk reaches EOF on its input, it will execute its END block (if there is one) and then exit, and this will close the pipe. That will then cause the next process in the pipeline to read EOF.

If you want the awk script to send EOF earlier than that, it will have to exit, by using the exit statement.

Barmar
  • 741,623
  • 53
  • 500
  • 612