Unexpected EOF while looking for matching '

I’m trying to run a series of restic restore commands to extract specific files from a restic repo on my linux NAS.

Here is a screenshot of what the script looks like with the filenames cutoff intentionally.

Note that in nano, if there is open quotes, the rest of the line with the open quote will be colored grey, otherwise if all the quotes are closed the line looks yellow. Initially when I copy+pasted these commands into this file from Windows via SSH, there was quite a few grey lines as some of the filenames had apostrophes in them, which I fixed manually by putting a backslash before each apostrophe.

Before running the script, I made sure to run dos2unix on the .sh file so that issues with Windows carriage return don’t cause issues. It made no difference to the errors.

extract.sh: line 64: unexpected EOF while looking for matching `‘’
extract.sh: line 65: syntax error: unexpected end of file

Any idea what might be causing this?

It’s probably something simple, but should be on/around line 64/65. Look for unescaped quotes, you might have a ’ in one of the filenames? Hard to say without actually having the file to look at myself.

I checked very thoroughly that this is not the case. There was 3 unescaped quotes in the file that I went through and fixed.

I’m suspecting that this may be just misleading debug data, as it does not give me errors if I just delete the whole directory structure before each extraction. I think it’s basically saying “restic refuses to try to merge this folder” but in very unrelated terms.

I could be wrong but the way I read the message it’s from the shell itself and there’s no restic involved yet.

If you remove/comment lines 62+, does the error still persist? By removing/commenting out lines you can identify which one(s) are the cupruit.

I should have copied the whole command, now I changed the script to something quite different so I don’t think I will get a similar error. I do know that clearly the last line didn’t fix it. Literally the entire script was in the screenshot and all lines were yellow, which should mean all quotes are closed properly.

Alright, well next time it might be a good idea to isolate the problem to the line that triggers it. That will give you information so you can focus on that specific line and hopefully find the cause. What nano thinks of the contents of the file is not synonymous with what bash things about the contents of the file, hence you need to focus on the latter (IMO).

The debug info was simply not helpful. It would default to the last line regardless of what was at the end. Repeatedly I ran dos2unix, or swapped lines around, or deleted the last line, and it always told me unexpected EOF at the last line.

You found the cause of the problem, right? :eyes:

Yup.

1 Like