function keyword is non-standard. Delete it.

SC2112 – ShellCheck Wiki

See this page on GitHub

function keyword is non-standard. Delete it.

Problematic code:

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

Correct code:

#!/bin/sh
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.

  • Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
posted @ 2023-05-12 16:45  牧之丨  阅读(60)  评论(0编辑  收藏  举报