Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

I have the below shell script.

#!/bin/sh


i=1
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

It fails with below error.

28: /mtp-test/script.sh: Syntax error: end of file unexpected (expecting "fi"))

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Why does this error occur?

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading