Bash script error: "function: not found". Why would this appear? Bash script error: "function: not found". Why would this appear? unix unix

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


I faced the same problem, I then modified the syntax and it worked for me. Try to remove the keyword function and add brackets () after the function name.

#!/bin/bashsayIt(){      echo "hello world"}sayIt


ls -la /bin/sh

check the sym link where it point to bash or dash