pgindent vs dash

For those who don't know, pgindent is the tool used to indent the source code of PostgreSQL. dash is the shell that ships as /bin/sh on at least Ubuntu.

pgindent requires indent from BSD (we use a patched version from NetBSD, the source is available on the PostgreSQL ftp site), and specifically does not work with GNU indent. Guess what Ubuntu ships with.

The solution is of course a small script that runs BSD indent from a different directory, and also points out the typedefs.list file from the PostgreSQL git repo. Something like this:

#!/bin/sh

export PATH=src/tools/pgindent:$PATH
src/tools/pgindent/pgindent src/tools/pgindent/typedefs.list $*

Spot the error? Yeah, that calls /bin/sh, which is dash. Which gives some really interesting results with pgindent, none of which are what you expect.

So if you run pgindent through a script like this, be sure to use /bin/bash and not /bin/sh!


Comments

Interesting post, thank you.

As for the sh problem, the following shebang line should work:

!/usr/bin/env bash

Posted on Jan 18, 2011 at 17:03 by Hannes Just.

Oh, just using

!/bin/bash

works fine. It's /bin/sh that doesn't (and AFAIK it does work if /bin/sh is actually sh and not dash)

Posted on Jan 18, 2011 at 17:05 by Magnus.

Not every distribution will install bash in /bin. Some will install bash only in /usr/bin/bash, so hard-coding its path will fail on those systems.

Debian and Ubuntu are using the light-weight dash to speed up their boot process. It's not fully compatible with bash. It's not a requirement for distributions that /bin/sh actually is bash. Basically, /bin/sh just has to be smart enough to run init.d scripts. Therefore, if you depend on certain bash functionality (those fancy expansion features come to my mind), request bash instead of sh through the shebang.

Posted on Jan 18, 2011 at 17:27 by Hannes Just.

Conferences

I speak at and organize conferences around Open Source in general and PostgreSQL in particular.

Upcoming

Pycon Sweden
May 9-10, 2016
Stockholm, Sweden
PGCon
May 17-21, 2016
Ottawa, Canada
Stockholm PUG 2016/3
Jun 16, 2016
Stockholm, Sweden
PGDay UK 2016
Jul 05, 2016
London, UK
PG Day'16 Russia
Jul 6-8, 2016
St Petersburg, Russia
Stockholm PUG 2016/4
Aug 31, 2016
Stockholm, Sweden
Postgres Open
Sep 13-16, 2016
Dallas, USA
PGConf.EU 2016
Nov 1-Jan 4, 2016
Tallinn, Estonia

Past

Stockholm PUG 2016/2
Apr 26, 2016
Stockholm, Sweden
PGConf.US
Apr 18-20, 2016
New York, USA
pgDay Paris
Mar 31, 2016
Paris, France
Nordic PGDay
Mar 17, 2016
Helsinki, Finland
ConFoo
Feb 24-26, 2016
Montreal, Canada
More past conferences