
fc manual
Overview of the FC Command in Unix-like Shells
The fc builtin offers a quick interface to shell history‚ enabling listing‚ editing‚ and re‑execution of past commands. It is available in Bash‚ Zsh‚ and Korn shells‚ and its syntax mirrors the original Unix implementation‚ providing flags for selection and display. design simplifies command recall‚ productnow
Definition and Purpose of fc
In Unix‑like shells‚ the fc builtin is a history editor and re‑execution tool that lets users view‚ modify‚ and run previous commands directly from the command line. The name “fc” stands for “fix command” or “file command‚” reflecting its original role in early Unix shells as a means to correct or replay commands. When invoked without options‚ fc opens the user’s default editor (as specified by the FCEDIT environment variable or the EDITOR variable) with a list of recent history entries‚ allowing the user to edit them in place. After saving and closing the editor‚ the edited command is executed automatically‚ making it a powerful shortcut for correcting typos‚ adding options‚ or re‑running complex commands with minimal typing. The builtin is available in Bash‚ Zsh‚ and KornShell‚ and its syntax closely follows the original implementation‚ providing options like -l to list entries‚ -n to suppress line numbers‚ and -r to reverse the order. It supports the -e option to specify a custom editor‚ giving users control !. By default‚ fc operates on the most recent 16 commands‚ but this range can be adjusted with the HISTSIZE variable. The primary purpose of fc is to streamline workflow by reducing repetitive typing and enabling quick edits of command history‚ which is especially useful in interactive sessions where commands are frequently modified or re‑executed. Its integration with the shell’s history mechanism makes it a core tool for power users who rely on efficient command recall and editing‚ a staple in advanced shell scripting. Users often combine fc with HISTCONTROL and HISTIGNORE to fine‑tune which commands appear in history‚ keeping entries

Historical Adoption in Bash and Zsh

When the Bourne shell (sh) was extended in the early 1980s‚ the fc builtin was introduced as a lightweight history editor‚ allowing users to fix and re‑execute commands without leaving the terminal. Its design was inspired by the original Unix 7‑th edition shell‚ where fc served as a simple interface to the command history file. As Bash emerged in 1989 as replacement for the proprietary Korn shell‚ it adopted fc almost verbatim‚ preserving the same syntax and semantics. Bash’s implementation added support for the -e option to specify an editor‚ and the -l‚ -n‚ and -r flags for listing history entries‚ features that were absent in original sh. This made fc a powerful tool for interactive users‚ and it quickly became a staple in Bash documentation and tutorials. Zsh‚ released in 1990‚ followed a similar path. It incorporated fc as part of its extensive set of builtins‚ ensuring compatibility with scripts that relied on Bash’s history editing capabilities. Zsh’s implementation extended the functionality further by allowing the -s flag to re‑execute a command without editing‚ and by integrating fc with its own history expansion features. Over the years‚ both shells have maintained backward compatibility with original fc behavior while adding enhancements that reflect each shell’s design philosophy. Today‚ fc remains a core component of both Bash and Zsh‚ widely used by developers for quick command correction and efficient workflow automation. The historical adoption of fc demonstrates how a simple effective tool can evolve across different shell environments‚ providing a consistent user experience while adapting to new features and user expectations in practice daily.

Syntax and Basic Usage of fc
fc [options] [first] [last] opens the default editor on selected history lines‚ then re‑executes the edited command. Common flags: -l lists entries‚ -n omits line numbers‚ -r reverses order‚ -e editor specifies editor. Without arguments‚ fc edits the most recent command. Use -l to list‚ -n to hide numbers.!!

Listing History Entries

The fc builtin provides several options for displaying command history. When invoked with the -l flag‚ it prints a numbered list of the selected history entries‚ allowing the user to see the exact sequence of commands that have been executed. The default range is the most recent command‚ but the user can specify a first and last argument to narrow the output. For example‚ fc -l 10 20 will list entries 10 through 20 from the history file. The -n flag suppresses the line numbers‚ producing a cleaner list that can be piped to other utilities. The -r flag reverses the order‚ showing the oldest command first‚ which is useful when reviewing a long session. In addition‚ the -e option can be combined with -l to edit the selected entries before re‑execution; the editor is invoked with the history lines preloaded‚ and upon saving‚ the commands are executed in the order they appear. The history list is maintained in a file (typically ~/.bash_history for Bash) and can be configured with the HISTSIZE and HISTFILESIZE environment variables. The fc command respects these settings‚ ensuring that only the most recent commands are displayed; Advanced users may use the HISTCONTROL variable to filter duplicate or empty entries from the list. By mastering these options‚ users can efficiently navigate and manage their command history‚ reducing repetitive typing and improving workflow efficiency in Unix‑like shells. Users can also redirect the output of fc to a file by using shell redirection‚ enabling archival of command logs. The history can be cleared with the history -c command‚ which fc respects when listing. When scripting‚ the fc -p option preserves the history across subshells. Some shells allow setting the HISTCONTROL=ignorespace to skip commands starting with a space‚ which fc will honor. Finally‚ fc can be aliased to a custom name to provide a more descriptive command for frequent use.
Editing and Re-executing Commands
The fc builtin is not only a viewer; it can launch an editor to modify past commands before they run again. By default‚ fc opens the editor defined by the FCEDIT environment variable‚ falling back to EDITOR or vi if neither is set. The user edits the selected history lines in the editor‚ and upon saving and exiting‚ fc automatically re‑executes the modified commands in the original shell. This behavior is controlled by the -e option: fc -e nano 5 5 would open the fifth history entry in nano‚ allowing quick correction of a typo. If the user aborts the editor (for example‚ by pressing Ctrl‑C or closing the editor window without saving)‚ fc aborts without running any commands; The -s flag offers a shortcut: fc -s old=new substitutes old with new in the most recent command and executes it immediately‚ without opening an editor. Similarly‚ fc -s 10 re‑executes history entry 10. When multiple substitutions are needed‚ the user can chain them: fc -s old1=new1 -s old2=new2. Advanced usage includes combining -l with -e to edit a range of commands: fc -l -e vim 1 3 lists entries 1‑3‚ opens vim‚ and runs the edited block. The re‑execution respects options like set -o histexpand and set -o history‚ commands are saved. The re‑execution respects options like set -o histexpand and set -o history‚commands are saved.

Advanced Options and Customization
Advanced options let users tailor fc behavior. The -e flag selects an editor‚ -l lists entries‚ -n omits line numbers‚ -r reverses order‚ and -s performs substitutions. These flags can be combined‚ enabling precise history editing and execution control. Users can also export FCEDIT to specify a custom editor!!!
Editor Selection with -e
The -e option in the fc builtin allows the user to specify which editor should be invoked when editing a command from history. By default‚ fc uses the editor defined in the FCEDIT environment variable; if FCEDIT is unset‚ it falls back to the value of the VISUAL variable‚ and finally to the editor defined by the EDITOR variable. If none of these variables are set‚ the builtin will try to use vi as a last resort. The syntax for using the -e flag is straightforward: fc -e <editor> [first] [last]. The <editor> argument can be any command that launches an editor‚ such as nano‚ emacs‚ or even a custom script that wraps an editor. When the user supplies an editor name‚ fc will launch that editor with the selected history line(s) preloaded into a temporary file. The user can then modify the command‚ save the file‚ and exit the editor. Upon exit‚ fc will read the modified command back from the temporary file and execute it. If the user exits the editor without saving‚ fc will abort the operation and no command will be executed. It is possible to use a single dash (-) as the editor should be used. This can be handy when the user wants to temporarily override the default editor without changing environment variables. Additionally‚ the -e flag can be combined with other options such as -l for listing or -n for omitting line numbers‚ allowing for flexible history manipulation. The fc builtin also supports specifying an editor that accepts command-line arguments; for example‚ fc -e "nano -w" will launch nano with the -w flag. This flexibility makes fc a versatile tool for shellusers.
Listing Flags: -l‚ -n‚ -r
The fc builtin’s listing capabilities are controlled by three primary flags: -l for listing‚ -n to suppress line numbers‚ and -r to reverse the order of the displayed entries. When invoked without any arguments‚ fc defaults to listing the most recent command. The -l flag forces a list output even if the command would normally be edited; it accepts optional first and last arguments to narrow the range. By default‚ the list shows each entry prefixed with its history number‚ making it easy to reference specific commands with !. The -n flag removes these numbers‚ producing a cleaner view that is useful when piping the output to other tools or scripts. Combining -l and -n yields a plain list of commands without numbering. The -r flag reverses the order of the listed entries‚ so that the oldest command appears first. This is particularly handy when reviewing long sessions or when the user wants to see the earliest commands that led to a particular state. The flags can be combined in any order; for example‚ fc -l -r -n 1 10 lists commands 1 through 10 in reverse order without numbers. When no first or last is supplied‚ fc uses the default range of the most recent command. The combination of these flags provides a flexible‚ scriptable interface to the shell’s history‚ enabling both quick inspection and automated processing of past commands. These options make fc a strong tool for managing history.

Intelligent Stepper Motor Stages Command Interface Manual (FCStepper)
FCStepper offers a C++ API to manage stepper stages. The constructor creates an instance‚ while open and close handle serial communication. listDevices returns available units‚ and setMicroStep configures micro‑step factors perfull.step.
Creating an Instance with the Constructor
To begin interacting with an Intelligent Stepper Motor Stage‚ the first step is to instantiate the FCStepper class. The constructor accepts optional parameters that allow the user to specify a serial port‚ baud rate‚ and a timeout value. If no arguments are supplied‚ the library will attempt to auto‑detect the first available device and use a default baud rate of 115200 with a 2000‑millisecond timeout. The signature is typically:
FCStepper::FCStepper(const std::string &port = ""‚ unsigned int baud = 115200‚ unsigned int timeout = 2000);
Internally‚ the constructor performs several critical tasks:
- Validates the provided port string; if empty‚ it scans common serial device paths such as
/dev/ttyUSB0orCOM3. - Initializes a
SerialPortobject‚ configuring it with the desired baud rate and timeout. - Attempts to establish a connection; if the port is busy or inaccessible‚ it throws a
std::runtime_errorwith a descriptive message. - Queries the device for its firmware version and capabilities‚ storing this information in member variables for later reference.
- Sets an internal flag
isConnected_totrueupon successful handshake.
Example usage:
try {
FCStepper stepper("/dev/ttyUSB1"‚ 115200‚ 3000);
if (stepper.isConnected) {
std::cout << "Stepper initialized: firmware " << stepper.getFirmware << std::endl;
}
} catch (const std::exception &e) {
std::cerr << "Initialization failed: " << e.what << std::endl;
}
By encapsulating the connection logic within the constructor‚ the library ensures that any instance of FCStepper is immediately ready for command transmission‚ simplifying subsequent API calls such as moveTo or setMicroStep. Proper error handling during construction prevents the application from proceeding with an invalid or unconnected device‚ thereby reducing runtime failures.
Thread safety is considered by guarding the serial port with a mutex‚ ensuring that concurrent calls from multiple threads do not corrupt the communication stream. The constructor also registers a cleanup handler that will automatically close the port when the FCStepper object is destroyed‚ preventing resource leaks.
When the constructor fails to open the specified port‚ it falls back to the next available port in the auto‑detect sequence. This fallback mechanism is useful in environments where multiple USB‑to‑serial adapters are present‚ ensuring that the application can still communicate with a stage without manual intervention.
Opening and Closing Communication with Devices
The FCStepper class provides explicit open and close methods to manage the serial link to a stepper stage. The open routine accepts a device identifier (e.g.‚ /dev/ttyUSB0 or COM3) and optional baud rate and timeout. It performs a handshake by sending a GETVER query and awaiting a firmware string; if the response matches‚ the connection is marked active and the internal isConnected_ flag is set to true. Failure to receive a valid reply triggers an exception‚ allowing the caller to retry with a different port or configuration.
Conversely‚ close terminates the link cleanly. It first sends a DISCONNECT command‚ then flushes the serial buffer and closes the file descriptor. Afterward‚ isConnected_ is reset to false‚ preventing accidental command transmission on a closed channel. The method returns a boolean indicating success‚ which can be used to confirm that the device has been safely powered down.
Both methods are thread‑safe; they lock a mutex before accessing the serial port. The open function also records the timestamp of the last successful handshake‚ which can be queried via lastConnected for diagnostic purposes.
In addition to control‚ the library offers a autoOpen helper that scans common serial paths‚ attempts to open each one‚ and returns the first successful instance. This is useful in test rigs where the device may be plugged into any USB port.
For debugging‚ the library exposes a debugLog method that writes raw command and response pairs to a user stream‚ aiding troubleshooting!!

Device Querying and Microstep Configuration
The FCStepper API offers listDevices to enumerate serial ports matching the controller’s VID/PID. Once a device is chosen‚ setMicrostepFactor sends a SETMS command to adjust the step ratio‚ updating settings. for motioncontrol
Retrieving the List of Connected Devices
To discover which FCStepper units are currently reachable‚ invoke the listDevices method on an instantiated object. The method performs a serial‑bus scan‚ matching vendor and product identifiers defined in the controller firmware. The returned array contains descriptive strings such as “/dev/ttyUSB0 – FCStepper v1.2” or “COM3 – FCStepper v1.0”‚ allowing the user to select the desired port for subsequent communication. The function is synchronous and blocks until the scan completes‚ ensuring that the list reflects the real‑time state of the host’s ports. If no devices are found‚ an empty array is returned‚ and the caller should handle this case gracefully‚ possibly prompting the user to reconnect hardware or check cable connections. Example usage:
const stepper = new FCStepper;
const devices = stepper.listDevices;
console.log(devices);
When the array is populated‚ the next step is to open a connection using open(devicePath)‚ which establishes a serial link and verifies firmware compatibility. The list function is a core part of the FCStepper API‚ enabling automated discovery in scripts and GUIs alike.
Setting Micro Step per Full Step Factor
To configure the micro‑stepping resolution of an FCStepper‚ invoke the setMicroStepFactor(factor) method after establishing a connection with open. The factor parameter accepts integer values that correspond to the controller’s supported micro‑step modes: 1 for full step‚ 2 for half step‚ 4 for quarter step‚ 8 for eighth step‚ 16 for sixteenth step‚ and 32 for thirty‑second step. The method transmits a vendor‑specific command packet to the device‚ encoded as a two‑byte sequence where the high byte contains the command identifier (0xA1) and the low byte carries the factor value. Upon receipt‚ the controller acknowledges with a status byte; a value of 0x00 indicates success‚ while any non‑zero value triggers an error callback. Example usage in JavaScript follows: const stepper = new FCStepper; stepper.open('/dev/ttyUSB0').then( => { return stepper.setMicroStepFactor(8); }).then( => { console.log('Micro‑step factor set to 1/8'); }).catch(err => { console.error('Failed to set micro‑step factor:'‚ err); }); When the factor is changed‚ the motor’s stepping frequency and torque characteristics adjust accordingly; higher micro‑step values yield smoother motion at the expense of reduced peak torque. It is recommended to consult the controller’s manual for the exact command syntax‚ as some firmware versions may require a preceding reset or setAcceleration call to apply the new resolution. Additionally‚ the API exposes a getMicroStepFactor method that returns the current setting‚ allowing scripts to verify that the desired resolution has been applied before proceeding with motion commands. The API ensures the micro‑step factor is applied atomically!!
