Jump to content

syntax error: unexpected end of file (issue with if $x = true)


Recommended Posts

for some reason a script I have fails with a syntax error. Unfortunately no further explanation of what or where the syntax error is:

~$ sudo bash *****.bash test1 *****.bash: line 13: syntax error: unexpected end of file

I have been able to reproduce the issue with this minimal script:

#!/bin/bash # option vars silentInstallation=true # work in progress apt_options=() echo "test1" if [ "$silentInstallation" = true ] then echo "choosing silent installation" apt_options=(-qq) fi echo "updating packages"

The script seems to do fine until if [ "$silentInstallation" = true ]

I have looked at other questions but cannot find the following things:

no open parentheses

no unclosed if statement

no missing line break

I am quite sure this script worked before.

Just now, sanctiondecision said:

for some reason a script I have fails with a syntax error. Unfortunately no further explanation of what or where the syntax error is:

~$ sudo bash *****.bash test1 *****.bash: line 13: syntax error: unexpected end of file

I have been able to reproduce the issue with this minimal script:

#!/bin/bash # option vars silentInstallation=true # work in progress apt_options=() echo "test1" if [ "$silentInstallation" = true ] then echo "choosing silent installation" apt_options=(-qq) fi echo "updating packages"

The script seems to do fine until if [ "$silentInstallation" = true ]

I have looked at other questions but cannot find the following things:

no open parentheses

no unclosed if statement

no missing line break

I am quite sure this script worked before.

Unexpected end of file error

thanks in advance for any help

Link to comment
Share on other sites

[ @sanctiondecision ]
---

Quote

unexpected end of file

Judging from this, it looks like the bash file you created has a problem with EOL (End of Line). Since bash is based on UNIX, you need to do EOL conversion from DOS to UNIX. The difference: DOS (Windows) uses CRLF as it's end of line, UNIX (Linux) uses LF and Machintosh uses CR.
---
Please put your code under "Code (<>)" markings for readability.
---

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.