[clug] Use 'fc' to fix commands

Brendan Jurd direvus at gmail.com
Wed Feb 19 01:32:07 MST 2014


Hi cluggers,

I only just recently stumbled across the wonderful 'fc' bash built-in
and wanted to pass on the tip in case I'm not the only one who didn't
know about it.

'fc' is for those times when you type out a long command in bash, like
a for loop, and when you hit Enter you find out that, you should have
double-quoted a variable, say, or escaped a space.  You can do `fc` to
open your recently fouled-up command in the $EDITOR of your choice.
When you save and exit, the now (hopefully) working command will be
executed.  If not, well you can just `fc` again until you get it
right.

In case the command you want to fix wasn't the most recently executed
one (after you screwed up the command you looked up a man page for
help and now you know what to do), `fc -l` will give a list of
recently executed commands and you can then `fc <id>` to fix it.

Happy bashing,
BJ


More information about the linux mailing list