Whatever using "gedit" command or "cat" command to edit sh function,the result is always syntax error. os:ubuntu 18.04 lts Code: #!/bin/sh function fun1() { echo -------- } fun1 ./xx.sh:2:syntax error: "(" unexpected Code: #!/bin/sh fun1() { echo -------- } fun1 ./xx.sh:4:syntax error: "}" unexpected ================================================================================ I known what is problem. it is /bin/sh -> dash,not /bin/sh -> bash
From the little knowledge I have about syntaxes regarding executing such script it might be the way you are running it that is having the issue. As long as you have the Shebang on the first line you are not supposed to encounter that error message. Try to execute the script using ./ followed by the filename and extension.
It's possible that the cat command might be putting something extra in that's upsetting the scripter. Try dumping the file to the console and see what's in the file.