From ca819deb29c9a9efeb9a5a0503b3c71914fc3a76 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Wed, 17 Oct 2018 20:38:59 -0700 Subject: [PATCH] Created SC2239 (markdown) --- SC2239.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 SC2239.md diff --git a/SC2239.md b/SC2239.md new file mode 100644 index 0000000..1bb7bdb --- /dev/null +++ b/SC2239.md @@ -0,0 +1,38 @@ +## Ensure the shebang uses the absolute path to the interpreter. + +### Problematic code: + +```sh +#!bin/sh +echo "Hello World" +``` + +### Correct code: + +```sh +#!/bin/sh +echo "Hello World" +``` + +### Rationale: + +The script's interpreter, as specified in the shebang, does not start with a `/`. + +The interpreter should always be specified by absolute path to ensure that the script can be executed from any directory. When it's not, it's generally a typo like in the problematic example. + +If you don't know where the interpreter is and you hoped to use `#! bash`, this is not an option. Use `/usr/bin/env` instead: + +```sh +#!/usr/bin/env bash +echo "Hello World" +``` + +While not required by POSIX, `env` can essentially always be found in `/usr/bin` and will search the PATH for the specified executable. + +### Exceptions: + +None. + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc! \ No newline at end of file