Bash script error: "function: not found". Why would this appear?
Chances are that on your desktop you are not actually running under bash
but rather dash
or some other POSIX-compliant shell that does not recognize the function
keyword. The function
keyword is a bashism, a bash extension. POSIX syntax does not use function
and mandates the use of parenthesis.
$ more a.sh#!/bin/shfunction sayIt { echo "hello world"}sayIt$ bash a.shhello world$ dash a.sha.sh: 3: function: not foundhello worlda.sh: 5: Syntax error: "}" unexpected
The POSIX-syntax works in both:
$ more b.sh#!/bin/shsayIt () { echo "hello world"}sayIt$ bash b.shhello world$ dash b.shhello world