Syntax Error: End of File Unexpected (Expecting "Then")

Syntax error: end of file unexpected (expecting then)

I have met the same problem. And the problem is the format of the file is "dos", but in linux shell requires "unix", so I install the "dos2unix"

$ sudo apt-get install dos2unix

or if you use emacs, you can do this:

C-x RET f unix

Good luck
:)

Syntax error: end of file unexpected (expecting fi)

You incorrectly closed here document. When youw rite:

expect <<EOF

The line has to be exactly EOF. No spaces before and after it. Exactly EOF. You want:

    expect << EOF
spawn ...
^^^^ - these spaces are "preserved"
EOF
^ also no spaces after!

You can use -<delimiter> and then it will ignore leading tabs. Not spaces.

    expect <<-EOF
spawn /usr/bin/scp $FULL $HOST:$DST
...
EOF
^^^^ - this is a tab character

Research a here-document in shell.

Shell Script Syntax Error: Unexpected End of File

Edit: Note that the original post has been edited since this answer was written and has been reformatted. You should look at the history to see the original formatting to understand the context for this answer.

This error occurs often when you have mismatched structure - that is, you do not have matching double quotes, matching single quotes, have not closed a control structure such as a missing fi with an if, or a missing done with a for.

The best way to spot these is to use correct indentation, which will show you where you have a broken control structure, and syntax highlighting, which will show you where quotes are not matched.

In this particular case, I can see you are missing a fi. In the latter part of your code, you have 5 ifs and 4 fis. However you also have a number of other problems - your backquoted touch /tmp/alert.txt... command is syntactically invalid, and you need a space before the closing bracket of an if test.

Clean up your code, and errors start to stand out.

Syntax error : end of file unexpected (expecting fi)

Try adding a semicolon after cat testFile. For example:

read: 
if [ -e testFile ] ; then cat testFile ; fi

alternatively:

read:
test -r testFile && cat testFile

Syntax error: fi unexpected (expecting then) in bash script

You can try

$ dos2unix /home/pi/sh/test.sh

and run it again.

Bash syntax error: unexpected end of file

I think file.sh is with CRLF line terminators.

run

dos2unix file.sh

then the problem will be fixed.

You can install dos2unix in ubuntu with this:

sudo apt-get install dos2unix

Syntax error: end of file unexpected (expecting fi))

I tried by removing the space/tab before "EOF" as shown below and it worked. I am not sure why space creates an issue.

#!/bin/sh
i=1
label='Mod_Name'
for label in 'Mod_Name' 'Issue No' 'UT Status' 'Dev ID' 'Loc'; do
if ! grep -q "^ $((i++)). $label:" $1; then
cat <<- EOF
Proposed message does not satisfy this repository's exacting standards
It must match the template:
1. Mod_Name: xxx
2. Issue No: xxx
3. UT Status: xxx
4. Dev ID: xxx
5. Loc: xxx

The proposed message does not contain the label: $label" >&2
EOF
exit 1
fi
done

Syntax error: ( unexpected (expecting then)

Just use an or in the test, or escape the parentheses in the regular expression. Also, there's no need to test for case with nocasematch set; and with that requirement out of the way, you don't even need the regular expression.

shopt -s nocasematch
...
if [[ "$response" = "yes" || "$response" = "y" ]]

Syntax error: end of file unexpected (expecting do)

If it should be an infinite loop try

while [ 1 = 1 ]
do
nohup php retrieve4.php 1 > /dev/null 2>&1 &
nohup php retrieve4.php 2 > /dev/null 2>&1 &
done

EDIT

while [ 1 ] 
do
echo 'test'
done

This is running perfectly well on my setup. Therefore I'd expect your method of running the script is wrong

You could also try something like this:

while true ; do php my_script.php ; done > /dev/null


Related Topics



Leave a reply



Submit