Tag Archives: Linux common commands

file_name.sh: 3: Syntax error: “(“ unexpected [How to Solve]

An error was encountered

Execute the command $./example03. Sh error:
./example03. Sh: 3: syntax error: “(” unexpected
check the document

#!/bin/sh
#function hello
function hello(){
    echo "hello SXU."
}
#main
hello	
exit 0

Confirm again and again that there is no error.

Find the reason

Related to the actual shell version used
use the command LS - L/bin/* sh to print and view. For example:
you can see that SH is redirected to dash. Therefore, if./example.sh is executed, dash is used.

Solution:

bash example. Sh the first line of the script #/ Change bin/sh to: #/ Bin/bash, and then execute./example. Sh. The code is correct for standard bash, because Ubuntu/Debian uses dash instead of traditional bash in order to speed up startup. The solution is to cancel Dash: sudo dpkg reconfigure dash , and select no in the selection, choose one of the three methods to succeed.