I just came across the fc command which lets you edit the previous command and issue it afterwards.

It has its own FCEDIT environment variable for setting its editor, and a man page in POSIX Programmer's Manual (1p).

It creates a file in /tmp directory and executes the contents if the file is saved (:wq in vim).

Apart from that, it can number and list fc -l previously executed commands to choose from.

So it's really nice and handy command to know.

The question is what does its name really mean; how to associate the command with its function in mind?

"First-class"? or maybe even just as "Function" (what came to my mind after composing the previous sentence)?

The manual refers to it simply as "the fc utility".

  • 2
    Thanks for asking this; I have wondered for a long time what the mechanism that pressing ^X,^E used to perform that function. – DopeGhoti Jun 15 '17 at 20:56
  • 1
    See also Export Command History into a Shell Script. – Stephen Kitt Jun 15 '17 at 21:36
  • Theres a lot of cool history expansions you can do as well... !! is the previous command, !-2 is the command before that, !-3 to !-N etc. Then !:1 gives you the first argument from the previous command, !:2, the second argument, !* all the arguments, ^command1^command2 execute last command1 replacing instance of command1 with command2, etc. – Charles Addis Jul 27 '17 at 7:32
  • there's also a similar third-pary command with predictive improvements. – user86041 Sep 16 '17 at 13:36

Although the zshbuiltins(1) man page does not indicate it, the fc command is pretty much the same as its bash counterpart. Simply (F)ix (C)ommand.

  • Thank. It makes sense and sounds perfect. I switched to bash issuing help fc (help being a utility for shell built-ins) but the output doesn't note that too, and neither whatis fc. – user86041 Jun 15 '17 at 21:11
  • 2
    You could try man bash or man builtins. Or view linux.die.net/man/1/bash. – Deathgrip Jun 15 '17 at 21:14
  • 6
    fc is a POSIX command,which originated in ksh AFAIK (already there in ksh86, already called fix command back then). zsh has had it since the first release in 1990. I don't know about bash. bash 1.05 didn't have it. – Stéphane Chazelas Jun 15 '17 at 21:16
  • Great! I had to confirm that :P – user86041 Jun 15 '17 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy