A ignorant question, suppose i type "fc 89" in a terminal, which will take me into a text editor, after i modify the command, how can i exit the editor and execute the command? Thanks for answering...

Dani AI

Generated

Short answer for : the shell opens whatever editor it is configured to use; as observed, that might be nano on one machine but something else on another. The editor choice is what determines how you save and quit so fc can then re-run the edited history entry.

To see and change the editor fc will invoke (bash):

echo "$FCEDIT"
echo "$EDITOR"

If neither variable is set, the shell falls back to a line editor. To override just this one edit, use fc with the -e option. To make a persistent change, export the variable in your shell startup file:

fc -e vim        # use vim for this edit only
export EDITOR=vim
export FCEDIT=vim   # add to ~/.bashrc or ~/.profile for future logins

Common save/quit notes (other than nano, which was already mentioned): in vi/vim press Escape then use :wq to write and quit (or :q! to quit without saving). In emacs save with C-x C-s and exit with C-x C-c. In the classic line editor use w then q to write and quit. If you use a graphical editor that forks (so the command returns immediately), fc may not wait for you; use the editor's "wait" or "no-fork" option (or use a terminal editor) so fc runs the edited command only after you finish.

If fc does not run the edited command, confirm you actually saved the temp file and that the editor exited normally.

Recommended Answers

All 2 Replies

On my system, this opens the 'nano' editor. To close out of nano, press 'Ctrl-x'. If you changed your command, then hit 'y' and Enter to save the changes. Once you exit, the command will run.

Thanks for your answer

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.