Skip to content

file_shebang

First line of each file in scope must match the shebang regex. Pairs with executable_has_shebang (which checks shebang presence on +x files) — file_shebang checks shebang shape.

Default shebang: is ^#!, which only enforces presence; almost every useful config supplies a tighter regex pinning the interpreter.

OptionTypeRequiredDefaultDescription
shebangstring^#!Rust regex; the first line of every matched file must match. Default ^#! only enforces shebang presence.

Plus the common paths, level, id, and when fields. This table is generated from the JSON Schema; option types and defaults are authoritative.

The rule fires on this repository:

scripts/
scripts/hardcoded.sh
scripts/missing.sh
scripts/ok.sh
scripts/hardcoded.sh
#!/bin/bash
echo legacy
scripts/missing.sh
echo no shebang
scripts/ok.sh
#!/usr/bin/env bash
echo ok

With this .alint.yml:

version: 1
rules:
- id: scripts-use-env-bash
kind: file_shebang
paths: "scripts/*.sh"
shebang: '^#!/usr/bin/env bash$'
level: error

alint check reports:

Terminal window
--- scripts/hardcoded.sh -------------------------------------------------------
x error scripts-use-env-bash
1:1 first line "#!/bin/bash" does not match required shebang
/^#!/usr/bin/env bash$/
--- scripts/missing.sh ---------------------------------------------------------
x error scripts-use-env-bash
1:1 first line "echo no shebang" does not match required shebang
/^#!/usr/bin/env bash$/
Summary (2 violations):
x 2 errors
0 passing * 1 failing

This repository is compliant:

scripts/
scripts/build.sh
scripts/ci.sh
scripts/build.sh
#!/usr/bin/env bash
set -euo pipefail
echo ok
scripts/ci.sh
#!/usr/bin/env bash
echo ok

With this .alint.yml:

version: 1
rules:
- id: scripts-use-env-bash
kind: file_shebang
paths: "scripts/*.sh"
shebang: '^#!/usr/bin/env bash$'
level: error

alint check reports:

Terminal window
v All 1 rule(s) passed.