15.73. shebangfix

Possible arguments: (none)

A lot of software uses incorrect locations for script interpreters, most notably /usr/bin/perl and /bin/bash. The shebagngfix macro fixes shebang lines in scripts listed in SHEBANG_FILES. The shebangfix macro is run from ${WRKSRC}, so it can contain paths that are relative to ${WRKSRC}. It can also deal with absolute paths if files outside of ${WRKSRC} require patching. For example:

USES=	shebangfix
SHEBANG_FILES=	scripts/foobar.pl scripts/*.sh

Currently Bash, Java, Ksh, Lua, Perl, PHP, Python, Ruby, Tcl, and Tk are supported by default.

There are three configuration variables:


The list of supported interpreters.


The path to the command interpreter on FreeBSD. The default value is ${LOCALBASE}/bin/interp.


The list of wrong invocations of interpreters. These are typically obsolete paths, or paths used on other operating systems that are incorrect on FreeBSD. They will be replaced by the correct path in interp_CMD. This list will always be part of interp_OLD_CMD: "/usr/bin/env interp" /bin/interp /usr/bin/interp.

To add another interpreter, set SHEBANG_LANG. For example:


interp_OLD_CMD will contain multiple values. Any entry with spaces must be quoted. For example, if it was not already defined, the Ksh entry could be defined as:

ksh_OLD_CMD=	"/usr/bin/env ksh" /bin/ksh /usr/bin/ksh
ksh_CMD=	${LOCALBASE}/bin/ksh

Some software uses strange locations for an interpreter. For example, an application might expect Python to be located in /opt/bin/python2.7. The strange path to be replaced can be declared in the port Makefile:

python_OLD_CMD=	/opt/bin/python2.7


The fixing of shebangs is done during the patch phase. If scripts are created with incorrect shebangs during the build phase, the build process (for examples, the configure script, or the Makefiles) must be patched to generate the right shebangs. Correct paths for supported interpreters are available in interp_CMD.

All FreeBSD documents are available for download at http://ftp.FreeBSD.org/pub/FreeBSD/doc/

Questions that are not answered by the documentation may be sent to <freebsd-questions@FreeBSD.org>.
Send questions about this document to <freebsd-doc@FreeBSD.org>.