Skip to content
Jordan Christiansen edited this page Jan 9, 2025 · 4 revisions

function keyword is non-standard. Delete it.

Problematic code:

#!/bin/sh
function hello() {
  echo "Hello World"
}

Correct code:

#!/bin/sh
hello() {
  echo "Hello World"
}

The function keyword is a feature of Bash and Ksh, so code that uses it may be intended to be a Bash or Ksh script instead:

#!/bin/bash
function hello() {
  echo "Hello World"
}

Rationale:

function is a non-standard keyword that can be used to declare functions in Bash and Ksh.

In POSIX sh and dash, a function is instead declared without the function keyword as in the correct example.

Exceptions:

None.

Related resources:

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally