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
You can bind ESC to the Readline function unix-line-discard
:
bind '"\e": unix-line-discard'
To make the change permanent, add the command to ~/.xinputrc
:
printf "bind '\"\\\e\": unix-line-discard'\n" >>~/.xinputrc
And source ~/.xinputrc
in ~/.bashrc
:
printf 'source ~/.xinputrc\n' >>~/.bashrc
To load the change also in the current shell, source ~/.xinputrc
:
source ~/.xinputrc
This is a Bash feature, so it will work across any terminal, unless the terminal is hijacking the ESC key itself, for example if ESC is part of a terminal-specific keystroke, in which case you'll have to disable the offending keystroke in the terminal.
See also help bind
and bind -P
for a list of the available Readline functions and the keys / keystrokes they're currently bound to.
Best Answer
suspend
is a bash built-in command, what it does as per the man page is:Thus your shell is suspended and will be until you send it a
SIGCONT
signal. The behavior you see is because the shell is not interpreting those characters.To fix this:
use pkill to send the CONT signal to all processes named
bash
. This won't affect other running shells but should "unstick" the stuck one.pkill -CONT bash