When you press Enter at the end of:
for VARIABLE in file1 file2 file3
The shell can't execute anything since that for
loop is not finished. So instead, it will print a different prompt, the $PS2
prompt (generally >
), until you enter the closing done
.
However, after >
is displayed, you can't go back to edit the first line.
Alternatively, instead of typing Enter, you can type Ctrl-VCtrl-J. That way, the newline character (aka ^J
) is entered without the current buffer being accepted, and you can then go back to editing the first line later on.
In zsh
, you can press Alt-Enter or EscEnter to insert a newline character without accepting the current buffer. To get the same behavior in bash
, you can add to your ~/.inputrc
:
"\e\C-m": "\026\n"
(\026
being the ^V
character).
bash
you can use the keyboard combinationCtrl + x + e
to open the contents of the command prompt in a editor such as vim where you can work on it more easily, when you're done you can exit the editor and the command will run. – slm Jun 27 '13 at 00:22