Tag Archives: “syntax error near unexpected token `fi’”

Solve the problem of shell script “syntax error near unexpected token ` fi ‘”.

When executing the shell script, the following error is prompted:

After searching for information, I found:

carried out:

1
vi finddir.sh

Then, enter

1
set ff

The results are:

The solution is to modify it to unix:

1
set ff=unix

Execute the save command:

1
:wq

Execute again:

1
:set ff

Finally execute the command.

There is an error in this article, that is in the script

1
if [-d "$folder"]; then

To:

1
if [ ! -d "$folder" ]; then

Pro-test so good.