Shebang for psql

后端 未结 2 1195
春和景丽
春和景丽 2021-02-08 13:11

I\'m trying to write PostgreSQL script(s) but having a problem with shebang line

#! /usr/bin/psql [ psql_args_here ] -f

select now();

This giv

2条回答
  •  鱼传尺愫
    2021-02-08 13:29

    The problem is that psql don't skip the first line of the file.

    You could try

    #! /bin/sh
    exec sh -c "tail -n +3 $0 | psql -f -"
    
    select now();
    

    or simply

    #! /bin/sh
    psql << E_O_SQL
    
    select now();
    
    E_O_SQL
    

提交回复
热议问题