nbk
nbk

Reputation: 543

“unexpected error : bash unexpected end of file” from code with command in curly braces (group command)

I expected this file to echo "error" and exit. Why does it produce the unexpected end of file error instead? I used vim to create the file.

#!/bin/bash

{ eval "nothing" } || { echo "error" ; exit 1 }
echo "something"

Upvotes: 0

Views: 89

Answers (1)

chepner
chepner

Reputation: 531075

} is only special in command position. In your code, each } is just another argument to the preceding eval and exit commands. Nothing ever closed the opening {.

You need to first terminate the preceding commands explicitly, for example, with a ;.

{ eval "nothing"; } || { echo "error" ; exit 1; }
echo "something"

Upvotes: 3

Related Questions