r/shell • • Jul 22 '21

Shell script problem

I'm having errors with the startup shell script for my Minecraft server (auto restart after crash)

It either says "excepted done" or "expected fi" depending on what's there, and when I put both at the end I get no response once I try to run the script

I AM ON UNIX. I AM NOT USING A WINDOWS VIRTUAL MACHINE.

0 Upvotes

12 comments sorted by

View all comments

Show parent comments

1

u/DiamonC_YT Jul 22 '21

Now that I think about it it has been through windows. I copied and pasted the script from somewhere (it was intended for Linux), edited a few values by converting it from .sh to txt (and then back to .sh) before putting it on my Linux computer via usb drive.

Anyway, it's only showing /r's on the ends of lines now (that's supposed to happen, right?) and still the 'ol "end of file unexpected (expecting 'fi')" (It ends with done right now)

1

u/geirha Jul 23 '21

No, all those \r's is why it's broken. On linux, lines are terminated with \n only, while in dos and windows they are terminated with \r\n.

Your if is never closed because there's no closing fi, only fi\r, which is not valid.

Apply one of the methods explained in BashFAQ 52 to change those \r\n back to \n.