Tag Archives: Shell error

[Solved] shell Error: Syntax error: “(“ unexpected (expecting “}“)

The hard disk is damaged and the system is reinstalled. An error is reported when executing the previous script

Syntax error: “(” unexpected (expecting “}”)


ls -l /bin/sh

The default link is dash

Knowledge supplement

Bash: Unix shell written for GNU Project

SH: equivalent to /bin/bash –posix. It is bash that opens POSIX standard

Dash: it has faster execution speed than bash, but supports fewer statement leaves


Here, I have no requirements for the speed of script execution, only that it can be used, so I can change it to bash

cd /bin/; ln -sf bash /bin/sh



[Solved] Shell error: syntax error: unexpected end of file

Sometimes an error will be reported when executing the script:

[[email protected] shell]# sh -x test. sh  
+ $ ' \r '
: command not found
test. sh : line 37 : syntax error: unexpected end of file

reasons may be:

The text editor is the file written by Notepad or other editors under windows, and it runs in the cygwin simulation LINUX software environment.


The file format difference between DOS and Linux is caused.

The text file under DOS uses \r\n as the line break mark, expressed in hexadecimal is 0D 0A. The text file under Unix uses \n as a line break mark, which is 0A in hexadecimal.

[In windows, the two symbols used for line feed, carriage return \r, line feed symbol \n, under linux, only one symbol \n is enough .]

A text file in DOS format under Linux will display ^M at the end of the line when opened with a lower version of vi. Of course, you may not be able to see it, but in vi, the format of the file will be displayed below, “M.txt “[dos] 8L, 72C means a dos file format.


Use the following command to set the file format to unix format to solve the above error

vi test. sh 
:set fileformat = unix

Why can’t the script edited under windows be directly copied to the unix system and run directly?

Linux executes SHELL script error “syntax error near unexpected token `in”

long long ago….. Old teletypewriters used two characters to start a new line. One character moves the carriage back to the first position (called carriage return, <CR>, ASCII code 0D), and another character moves the paper up one line (called line feed, <LF>, ASCII code 0A). When computers came out, memory used to be very expensive. Some people think it is unnecessary to use two characters to indicate the end of a line. Unix developers decided that they could use a character to indicate the end of a line, Linux followed Unix, and it was also <LF>. Apple developers specified the use of <CR>. The guys who developed MS-DOS and Windows decided to use the old <CR><LF>.

Because MS-DOS and Windows use carriage return + line feed to represent line feed, so under Linux, use Vim to view the code written in VC under Windows. The “^M” symbol at the end of the line indicates a symbol.