17.82. shebangfix

Possible arguments: (none)

A lot of software uses incorrect locations for script interpreters, most notably /usr/bin/perl and /bin/bash. The shebangfix macro fixes shebang lines in scripts listed in SHEBANG_REGEX, SHEBANG_GLOB, or SHEBANG_FILES.

SHEBANG_REGEX

Contains one extended regular expressions, and is used with the -iregex argument of find(1). See Example 17.11, “USES=shebangfix with SHEBANG_REGEX.

SHEBANG_GLOB

Contains a list of patterns used with the -name argument of find(1). See Example 17.12, “USES=shebangfix with SHEBANG_GLOB.

SHEBANG_FILES

Contains a list of files or sh(1) globs. The shebangfix macro is run from ${WRKSRC}, so SHEBANG_FILES can contain paths that are relative to ${WRKSRC}. It can also deal with absolute paths if files outside of ${WRKSRC} require patching. See Example 17.13, “USES=shebangfix with SHEBANG_FILES.

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

There are three configuration variables:

SHEBANG_LANG

The list of supported interpreters.

interp_CMD

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

interp_OLD_CMD

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.

Note:

These will always be part of interp_OLD_CMD: "/usr/bin/env interp" /bin/interp /usr/bin/interp /usr/local/bin/interp.

Tip:

interp_OLD_CMD contain multiple values. Any entry with spaces must be quoted. See Example 17.9, “Specifying all the Paths When Adding an Interpreter to USES=shebangfix.

Important:

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 example, the configure script, or the Makefiles) must be patched or given the right path (for example, with CONFIGURE_ENV, CONFIGURE_ARGS, MAKE_ENV, or MAKE_ARGS) to generate the right shebangs.

Correct paths for supported interpreters are available in interp_CMD.

Tip:

When used with USES=python, and the aim is only to fix the shebangs but a dependency on Python itself is not wanted, use PYTHON_NO_DEPENDS=yes.

Example 17.8. Adding Another Interpreter to USES=shebangfix

To add another interpreter, set SHEBANG_LANG. For example:

SHEBANG_LANG=	lua

Example 17.9. Specifying all the Paths When Adding an Interpreter to USES=shebangfix

If it was not already defined, and there were no default values for interp_OLD_CMD and interp_CMD the Ksh entry could be defined as:

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

Example 17.10. Adding a Strange Location for an Interpreter

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

Example 17.11. USES=shebangfix with SHEBANG_REGEX

To fix all the files in ${WRKSRC}/scripts ending in .pl, .sh, or .cgi do:

USES=	shebangfix
SHEBANG_REGEX=	./scripts/.*\.(sh|pl|cgi)

Note:

SHEBANG_REGEX is used by running find -E, which uses modern regular expressions also known as extended regular expressions. See re_format(7) for more information.


Example 17.12. USES=shebangfix with SHEBANG_GLOB

To fix all the files in ${WRKSRC} ending in .pl or .sh, do:

USES=	shebangfix
SHEBANG_GLOB=	*.sh *.pl

Example 17.13. USES=shebangfix with SHEBANG_FILES

To fix the files script/foobar.pl and script/*.sh in ${WRKSRC}, do:

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

All FreeBSD documents are available for download at https://download.freebsd.org/ftp/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>.