From 904cc04561dbb1c118db643122fcb2ed2e0980c0 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 4 May 2024 14:44:08 -0700 Subject: [PATCH] Created SC2329 (markdown) --- SC2329.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 SC2329.md diff --git a/SC2329.md b/SC2329.md new file mode 100644 index 0000000..24eef74 --- /dev/null +++ b/SC2329.md @@ -0,0 +1,35 @@ +## This function is never invoked. Check usage (or ignored if invoked indirectly). + +### Problematic code: + +```sh +#!/bin/sh +f() { + echo "Hello World" +} +exit +``` + +### Correct code: + +```sh +#!/bin/sh +f() { + echo "Hello World" +} +f +exit +``` +### Rationale: + +ShellCheck found a function that goes out of scope before it's ever invoked. Verify that the function is called. It could be misspelled, or its invocation could also be unreachable (as in `f() { ..; }; exit; f`). + +Note that if the example script did not end in `exit`, this warning would not be emitted. This is because the function could be invoked by another script that `source`s it. + +### Exceptions: + +ShellCheck is currently bad at figuring out functions that are invoked via `trap`. In such cases, please [[ignore]] the message with a directive. + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc! \ No newline at end of file