Bash - executing commands in current shell

It is because you don't terminate the second line: { cmd1; cmd2; } is correct. The semicolon means "end of command".


To exec or not to exec

a call to exec replaces a shell's data, and therefore the shell can't return from an exec system call.

But not every command is the name of a program to execute. So often there is no exec call involved. The key distinction is that in contrast to ( cmd1; cmd2; ), you don't get another shell process. Or perhaps more correctly, the shell will only fork to execute child programs, not to execute shell processes.

Strange prompt

what does the command line belong.

As other answers have pointed out, your command was incomplete. So the command line belonged to bash itself, which was waiting for the end of your group.

Uses

Also, how is executing commands in the current shell in any way useful?

… as opposed to subshell grouping

The most prominent example is setting variables in that subcommand. Thy this:

foo=1; { foo=2; echo $foo; }; ( foo=3; echo $foo; ); echo $foo

This will print

2
3
2

So although you set foo=3 inside one group, that group was executed in a subshell and its settings didn't propagate to the parent.

Another thing worth considering is current working directory. { cd foo; make; } will leave you in directory foo whereas ( cd foo; make; ) will not alter the current working directory of your main shell.

… as opposed to ungrouped commands

The grouping is mostly useful if you have other code outside, e.g. conditionals

test -f foo && { echo "Foo exists."; rm foo; }

or redirections

{ echo "Content of $PWD:"; ls; } | gzip > dirlist.gz

The help builtin can be useful even for the { keyword. From help -m {:

NAME
    { ... } - Group commands as a unit.

SYNOPSIS
    { COMMANDS ; }

So, the semicolon (;) is mandatory after each command.