Shebang for psql [英] Shebang for psql

查看:93
本文介绍了Shebang for psql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写PostgreSQL脚本,但是shebang行有问题

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

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

select now();

这给了我一个错误,就好像我刚刚输入了 psql 在命令行中不包含任何参数。

This gives me error as if I just entered psql without any arguments in command line. How do I do it right?

推荐答案

问题是psql不会跳过文件的第一行。

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

您可以尝试

#! /bin/sh
exec sh -c "tail -n +3 $0 | psql -f -"

select now();

或简单地

#! /bin/sh
psql << E_O_SQL

select now();

E_O_SQL

这篇关于Shebang for psql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆