Monday, January 16, 2012

Ctrl-p and fc in bash

When you write a multi-line shell script directly on your terminal, like:

bash-3.2$ for i in 1 2 3 4
> do
> echo $i
> done
1
2
3
4

Hit Control-p on your keyboard next, and bash will turn your multi-line script into 1 line. i.e.:

bash-3.2$ for i in 1 2 3 4; do echo $i; done
And finally, if you use the command fc afterwards, it will take the script and put it into whatever $EDITOR you have set on your shell.

0 comments: