GNU Readline

Software library


title: "GNU Readline" type: doc version: 1 created: 2026-02-28 author: "Wikipedia contributors" status: active scope: public tags: ["free-software-programmed-in-c", "gnu-project-software", "text-user-interface-libraries", "termcap", "software-using-the-gnu-general-public-license"] description: "Software library" topic_path: "general/free-software-programmed-in-c" source: "https://en.wikipedia.org/wiki/GNU_Readline" license: "CC BY-SA 4.0" wikipedia_page_id: 0 wikipedia_revision_id: 0

::summary Software library ::

::data[format=table title="Infobox software"]

FieldValue
nameGNU Readline
logoHeckert GNU white.svg
logo size64px
authorBrian Fox
developerChet Ramey
released
latest release version
latest release date
latest preview version
latest preview date
programming languageC
genreLibrary
license2009: GPL-3.0-or-later
1997: GPL-2.0-or-later
1994: GPL-1.0-or-later
::

| name = GNU Readline | logo = Heckert GNU white.svg | logo size = 64px | author = Brian Fox | developer = Chet Ramey | released = | latest release version = | latest release date = | latest preview version = | latest preview date = | programming language = C | genre = Library | license = 2009: GPL-3.0-or-later 1997: GPL-2.0-or-later 1994: GPL-1.0-or-later GNU Readline is a software library that provides in-line editing and history capabilities for interactive programs with a command-line interface, such as Bash. It is currently maintained by Chet Ramey as part of the GNU Project.

It allows users to move the text cursor, search the command history, control a kill ring (a more flexible version of a copy/paste clipboard) and use tab completion on a text terminal. As a cross-platform library, readline allows applications on various systems to exhibit identical line-editing behavior.

History

Readline was created in 1988 by Free Software Foundation employee Brian Fox to implement line editing functionality required by POSIX for its shell. After the release of version 1.05, Fox passed control to Chet Ramey of Case Western who has been the sole maintainer since 1998.

Editing modes

Readline supports both Emacs and vi editing modes, which determine how keyboard input is interpreted as editor commands. POSIX prescribes the vi editing mode while leaving other editing modes unspecified and in the discretion of implementations. Readline originally included its Emacs editing mode due to the influence of Korn Shell's Emacs editing mode.

Emacs keyboard shortcuts

Emacs editing mode key bindings are taken from the text editor Emacs.

On some systems, must be used instead of , because the shortcut conflicts with another shortcut. For example, pressing in Xfce's terminal emulator window does not move the cursor forward one word, but activates "File" in the menu of the terminal window, unless that is disabled in the emulator's settings.

  • : Autocompletes from the cursor position.
  • : Moves the cursor to the line start (equivalent to the key ).
  • : Moves the cursor back one character (equivalent to the key ).
  • : Sends the signal SIGINT via pseudoterminal to the current task, which aborts and closes it.
    • Sends an EOF marker, which (unless disabled by an option) closes the current shell (equivalent to the command [exit](exit-command)). (Only if there is no text on the current line)
    • If there is text on the current line, deletes the current character (then equivalent to the key ).
  • : (end) moves the cursor to the line end (equivalent to the key ).
  • : Moves the cursor forward one character (equivalent to the key ).
  • : Abort the reverse search and restore the original line.
  • : Deletes the previous character (same as backspace).
  • : Equivalent to the tab key.
  • : Equivalent to the enter key.
  • : Clears the line content after the cursor and copies it into the clipboard.
  • : Clears the screen content (equivalent to the command [clear](clear-unix)).
  • : (next) recalls the next command (equivalent to the key ).
  • : Executes the found command from history, and fetch the next line relative to the current line from the history for editing.
  • : (previous) recalls the prior command (equivalent to the key ).
  • : (reverse search) recalls the last command including the specified characters. A second recalls the next anterior command that corresponds to the search.
  • : Go back to the next more recent command of the reverse search (beware to not execute it from a terminal because this command also launches its XOFF). If you changed that XOFF setting, use to return.
  • : Transpose the previous two characters.
  • : Clears the line content before the cursor and copies it into the clipboard.
  • : If the next input is also a control sequence, type it literally (e. g. * types "^H", a literal backspace).
  • : Clears the word before the cursor and copies it into the clipboard.
  • : Edits the current line in the $EDITOR program, or vi if undefined.
  • : Read in the contents of the inputrc file, and incorporate any bindings or variable assignments found there.
  • : Incremental undo, separately remembered for each line.
  • : Display version information about the current instance of Bash.
  • : Alternates the cursor with its old position. (C-x, because x has a crossing shape).
  • : (yank) adds the clipboard content from the cursor position.
  • : Sends the signal SIGTSTP to the current task, which suspends it. To execute it in background one can enter bg. To bring it back from background or suspension fg ['process name or job id'] (foreground) can be issued.
  • : Incremental undo, separately remembered for each line.
  • : (backward) moves the cursor backward one word.
  • : Capitalizes the character under the cursor and moves to the end of the word.
  • : Cuts the word after the cursor.
  • : (forward) moves the cursor forward one word.
  • : Lowers the case of every character from the cursor's position to the end of the current word.
  • : Cancels the changes and puts back the line as it was in the history.
  • : Capitalizes every character from the cursor's position to the end of the current word.
  • : Insert the last argument to the previous command (the last word of the previous history entry).

License

GNU Readline is notable for being a free software library which is licensed under the GNU General Public License (GPL). Free software libraries are far more often licensed under the GNU Lesser General Public License (LGPL), for example, the GNU C Library, GNU gettext and FLTK. A developer of an application who chooses to link to an LGPLv3 licensed library can use any license that does not: "restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications".{{cite web |url=https://www.gnu.org/copyleft/lesser.html |title=GNU Lesser General Public License |year=2007 |website=The GNU Lesser General Public License v3.0 - GNU Project |publisher=Free Software Foundation |accessdate=2011-09-03 |url=https://www.gnu.org/licenses/gpl-3.0.html |title=GNU General Public License |year=2007 |website=The GNU General Public License v3.0 - GNU Project |publisher=Free Software Foundation |accessdate=2011-09-03 |url=https://www.gnu.org/licenses/gpl-faq.html#IfLibraryIsGPL |title=Frequently Asked Questions about the GNU licenses |year=2010 |website=Frequently Asked Questions about the GNU Licenses - GNU Project |publisher=Free Software Foundation |accessdate=2011-09-03

This licensing was chosen by the FSF on the hopes that it would encourage software to switch to the GPL.{{cite web |url=https://www.gnu.org/licenses/why-not-lgpl.en.html |title=Why you shouldn't use the Lesser GPL for your next library |year=2016 |website=Why you shouldn't use the Lesser GPL for your next library - GNU Project - Free Software Foundation |publisher=Free Software Foundation |accessdate=2019-10-15 |url=https://clisp.cvs.sourceforge.net/viewvc/clisp/clisp/COPYRIGHT |title=CLISP copyright notice |year=1992 |publisher=CLISP repository |accessdate=2011-09-03 |url=https://gitlab.com/gnu-clisp/clisp/-/raw/master/doc/Why-CLISP-is-under-GPL |title=Why CLISP is under GPL |year=1992 |publisher=CLISP repository |accessdate=2023-01-19 |url=http://www.clisp.org/impnotes/faq.html#faq-gpl |title=License - why GNU GPL? |website=Frequently Asked Questions (With Answers) about CLISP |publisher=CLISP team |accessdate=2011-09-03

Another response has been to not use this in some projects, making text input use the primitive Unix terminal driver for editing.

Alternative libraries

Alternative libraries have been created with other licenses so they can be used by software projects which want to implement command line editing functionality, but be released with a non-GPL license.

  • Many BSD systems have a BSD-licensed libedit. MariaDB and PHP allow for the user to select at build time whether to link with GNU Readline or with libedit.
  • linenoise is a tiny C library that provides line editing functions. it is prominently used by MongoDB and Redis. It was integrated into Android in 2010, but has since been deprecated.
  • Haskeline is a BSD-3-Clause licensed readline-like library for Haskell. It is mainly written for the Glasgow Haskell Compiler, but is available to other Haskell projects which need line-editing services as well.
  • PSReadLine is a BSD-2-Clause licensed readline implementation written in C# for PowerShell inspired by bash and GNU Readline

Sample code

The following code is in C and must be linked against the readline library by passing a flag to the compiler:

::code[lang=cpp] #include <stdlib.h> #include <stdio.h> #include <readline/readline.h> #include <readline/history.h>

int main() { // Configure readline to auto-complete paths when the tab key is hit. rl_bind_key('\t', rl_complete);

// Enable history
using_history();

while (1) {
    // Display prompt and read input
    char* input = readline("prompt> ");

    // Check for EOF.
    if (!input)
        break;

    // Add input to readline history.
    add_history(input);

    // Do stuff...

    // Free buffer that was allocated by readline
    free(input);
}
return 0;

} ::

Bindings

Non-C programming languages that provide language bindings for readline include

  • Python's built-in module;
  • Ruby's built-in module;
  • Perl's third-party (CPAN) module, specifically for GNU ReadLine.
  • PHP's extension.

Support for readline alternatives differ among these bindings.

Notes

References

References

  1. Target, Sinclair. (August 22, 2019). "Things You Didn't Know About GNU Readline".
  2. (September 3, 2019). "Heroes in a Bash Shell". Red Hat.
  3. (2024). "sh — shell, the standard command language interpreter". The Open Group Base Specifications Issue 8 (IEEE Std 1003.1-2024).
  4. . (July 2, 2009). ["KSH88(1)"](http://www2.research.att.com/sw/download/man/man1/ksh88.html).
  5. "pty(7) - Linux manual page".
  6. "editline(3) - NetBSD Manual Pages".
  7. [https://thrysoee.dk/editline/ Editline Library (libedit)]
  8. "MariaDB/server/blob/10.2/BUILD/SETUP.sh". MariaDB Foundation.
  9. "php/php-src/tree/master/ext/readline". The PHP Group.
  10. (10 May 2020). "antirez/linenoise".
  11. "The MongoDB Database".
  12. "Redis".
  13. (25 May 2010). "Android core".
  14. "Android's shell and utilities".
  15. "Applications and libraries". haskell.org.
  16. Judah Jacobson. "judah/haskeline: A Haskell library for line input in command-line programs".
  17. "PowerShell/PSReadLine: A bash inspired readline implementation for PowerShell".
  18. "Module: Readline (Ruby 3.2)".
  19. "PHP: Readline - Manual".

::callout[type=info title="Wikipedia Source"] This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page. ::

free-software-programmed-in-cgnu-project-softwaretext-user-interface-librariestermcapsoftware-using-the-gnu-general-public-license