GNU Readline

From Wikipedia, the free encyclopedia
(Redirected from Readline)

Template:Short description

Page Module:Infobox/styles.css has no content.

GNU Readline
[[Programmer|Original authorTemplate:Pluralize from text]]Brian Fox
[[Programmer|DeveloperTemplate:Pluralize from text]]Chet Ramey
Initial release1989; 37 years ago (1989)
Template:Infobox software/simple
Written inC
EnginePage Template:Plainlist/styles.css has no content.Template:EditAtWikidata
TypeLibrary
License2009: GPL-3.0-or-later[a]
1997: GPL-2.0-or-later[b]
1994: GPL-1.0-or-later[c]
WebsiteScript error: No such module "WikidataIB".
RepositoryPage Template:Plainlist/styles.css has no content.

Script error: No such module "Check for conflicting parameters".

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.[1] After the release of version 1.05, Fox passed control to Chet Ramey of Case Western who has been the sole maintainer since 1998.[1]Template:R/superscript[2]

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.[3] Readline originally included its Emacs editing mode due to the influence of Korn Shell's Emacs editing mode.[1]Template:R/superscript[4] Emacs is the default mode.[5]

Emacs keyboard shortcuts

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

On some systems, Script error: No such module "key". must be used instead of Script error: No such module "key"., because the Script error: No such module "key". shortcut conflicts with another shortcut. For example, pressing Script error: No such module "key". 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.

  • Script error: No such module "key". : Autocompletes from the cursor position.
  • Script error: No such module "key". : Moves the cursor to the line start (equivalent to the key Script error: No such module "key".).
  • Script error: No such module "key". : Moves the cursor back one character (equivalent to the key Script error: No such module "key".).
  • Script error: No such module "key". : Sends the signal SIGINT via pseudoterminal to the current task, which aborts and closes it.[d]
  • Script error: No such module "key".
    • Sends an EOF marker, which (unless disabled by an option) closes the current shell (equivalent to the command exit). (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 Script error: No such module "key".).
  • Script error: No such module "key". : (end) moves the cursor to the line end (equivalent to the key Script error: No such module "key".).
  • Script error: No such module "key". : Moves the cursor forward one character (equivalent to the key Script error: No such module "key".).
  • Script error: No such module "key". : Abort the reverse search and restore the original line.
  • Script error: No such module "key". : Deletes the previous character (same as backspace).
  • Script error: No such module "key". : Equivalent to the tab key.
  • Script error: No such module "key". : Equivalent to the enter key.
  • Script error: No such module "key". : Clears the line content after the cursor and copies it into the clipboard.
  • Script error: No such module "key". : Clears the screen content (equivalent to the command clear).
  • Script error: No such module "key". : (next) recalls the next command (equivalent to the key Script error: No such module "key".).
  • Script error: No such module "key". : Executes the found command from history, and fetch the next line relative to the current line from the history for editing.
  • Script error: No such module "key". : (previous) recalls the prior command (equivalent to the key Script error: No such module "key".).
  • Script error: No such module "key". : (reverse search) recalls the last command including the specified characters. A second Script error: No such module "key". recalls the next anterior command that corresponds to the search.
  • Script error: No such module "key". : 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 Script error: No such module "key". to return.
  • Script error: No such module "key". : Transpose the previous two characters.
  • Script error: No such module "key". : Clears the line content before the cursor and copies it into the clipboard.
  • Script error: No such module "key". : If the next input is also a control sequence, type it literally (e. g. * Script error: No such module "key". Script error: No such module "key". types "^H", a literal backspace).
  • Script error: No such module "key". : Clears the word before the cursor and copies it into the clipboard.
  • Script error: No such module "key". Script error: No such module "key". : Edits the current line in the $EDITOR program, or vi if undefined.
  • Script error: No such module "key". Script error: No such module "key". : Read in the contents of the inputrc file, and incorporate any bindings or variable assignments found there.
  • Script error: No such module "key". Script error: No such module "key". : Incremental undo, separately remembered for each line.
  • Script error: No such module "key". Script error: No such module "key". : Display version information about the current instance of Bash.
  • Script error: No such module "key". Script error: No such module "key". : Alternates the cursor with its old position. (C-x, because x has a crossing shape).
  • Script error: No such module "key". : (yank) adds the clipboard content from the cursor position.
  • Script error: No such module "key". : 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.
  • Script error: No such module "key". : Incremental undo, separately remembered for each line.
  • Script error: No such module "key". : (backward) moves the cursor backward one word.
  • Script error: No such module "key". : Capitalizes the character under the cursor and moves to the end of the word.
  • Script error: No such module "key". : Cuts the word after the cursor.
  • Script error: No such module "key". : (forward) moves the cursor forward one word.
  • Script error: No such module "key". : Lowers the case of every character from the cursor's position to the end of the current word.
  • Script error: No such module "key". : Cancels the changes and puts back the line as it was in the history.
  • Script error: No such module "key". : Capitalizes every character from the cursor's position to the end of the current word.
  • Script error: No such module "key". : 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".[7] But linking to a GPLv3 licensed library such as Readline requires the entire combined resulting application to be licensed under the GPLv3 when distributed, to comply with section 5 of the GPL.[8][9]

This licensing was chosen by the FSF on the hopes that it would encourage software to switch to the GPL.[10] An important example of an application changing its licensing to comply with the copyleft conditions of GNU Readline is CLISP, an implementation of Common Lisp. Originally released in 1987, it changed to the GPL license in 1992,[11] after an email exchange between one of CLISP's original authors, Bruno Haible, and Richard Stallman, in which Stallman argued[12] that the linking of readline in CLISP meant that Haible was required to re-license CLISP under the GPL if he wished to distribute the implementation of CLISP which used readline.[13]

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.[14][15] MariaDB and PHP allow for the user to select at build time whether to link with GNU Readline or with libedit.[16][17]
  • linenoise is a tiny C library that provides line editing functions.[18] As of 2025, it is prominently used by MongoDB and Redis.[19][20] It was integrated into Android in 2010, but has since been deprecated.[21][22]
  • Haskeline is a BSD-3-Clause licensed readline-like library for Haskell. It is mainly written for the Glasgow Haskell Compiler,[23] but is available to other Haskell projects which need line-editing services as well.[24]
  • PSReadLine is a BSD-2-Clause licensed readline implementation written in C# for PowerShell inspired by bash and GNU Readline[25]

Sample code

The following code is in C and must be linked against the readline library by passing a Page Template:Mono/styles.css has no content.-lreadline flag to the compiler:

#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 readline module;
  • Ruby's built-in readline module;[26]
  • Perl's third-party (CPAN) Term::ReadLine module, specifically Term::ReadLine::Gnu for GNU ReadLine.
  • PHP's extension.[27]

Support for readline alternatives differ among these bindings.

Notes

Page Template:Reflist/styles.css has no content.

  1. ^ GPL-3.0-or-later since version 6.0 (2009-02-20).
  2. ^ GPL-2.0-or-later from version 2.1 (1997-06-05) until version 5.2 (2006-10-11).
  3. ^ GPL-1.0-or-later from ? until version 2.0 (1994-08-04).
  4. ^ A part of pseudoterminals or PTYs (for Linux), which is evident from the terminal configuration tools such as stty; in typical Linux distribution the PTY master endpoint treats special characters as signals to be sent to slaves e.g.SIGINT[6]

References

Page Template:Reflist/styles.css has no content.

  1. ^ a b c Page Module:Citation/CS1/styles.css has no content.Target, Sinclair (August 22, 2019). "Things You Didn't Know About GNU Readline". Two-Bit History. Retrieved January 21, 2026.
  2. ^ Page Module:Citation/CS1/styles.css has no content.Saron Yitbarek (September 3, 2019). "Heroes in a Bash Shell". Command Line Heroes (Podcast). Red Hat. Event occurs at 24:38. Retrieved January 21, 2026.
  3. ^ Page Module:Citation/CS1/styles.css has no content."sh — shell, the standard command language interpreter". The Open Group Base Specifications Issue 8 (IEEE Std 1003.1-2024). 2024.
  4. ^ Compare Page Module:Citation/CS1/styles.css has no content."KSH88(1)". July 2, 2009. Archived from the original on November 5, 2015. Retrieved January 21, 2026.
  5. ^ Page Module:Citation/CS1/styles.css has no content."GNU Readline Library". December 30, 2024. The Readline default is emacs mode.
  6. ^ Page Module:Citation/CS1/styles.css has no content."pty(7) - Linux manual page". man7.org. Retrieved 2021-09-30.
  7. ^ Page Module:Citation/CS1/styles.css has no content."GNU Lesser General Public License". The GNU Lesser General Public License v3.0 - GNU Project. Free Software Foundation. 2007. Retrieved 2011-09-03.
  8. ^ Page Module:Citation/CS1/styles.css has no content."GNU General Public License". The GNU General Public License v3.0 - GNU Project. Free Software Foundation. 2007. Retrieved 2011-09-03.
  9. ^ Page Module:Citation/CS1/styles.css has no content."Frequently Asked Questions about the GNU licenses". Frequently Asked Questions about the GNU Licenses - GNU Project. Free Software Foundation. 2010. Retrieved 2011-09-03.
  10. ^ Page Module:Citation/CS1/styles.css has no content."Why you shouldn't use the Lesser GPL for your next library". Why you shouldn't use the Lesser GPL for your next library - GNU Project - Free Software Foundation. Free Software Foundation. 2016. Retrieved 2019-10-15.
  11. ^ Page Module:Citation/CS1/styles.css has no content."CLISP copyright notice". CLISP repository. 1992. Retrieved 2011-09-03.
  12. ^ Page Module:Citation/CS1/styles.css has no content."Why CLISP is under GPL". CLISP repository. 1992. Retrieved 2023-01-19.
  13. ^ Page Module:Citation/CS1/styles.css has no content."License - why GNU GPL?". Frequently Asked Questions (With Answers) about CLISP. CLISP team. Retrieved 2011-09-03.
  14. ^ Page Module:Citation/CS1/styles.css has no content."editline(3) - NetBSD Manual Pages". NetBSD. Retrieved 2022-09-13. Command Line Editor Library (libedit, -ledit)
  15. ^ Editline Library (libedit)
  16. ^ Page Module:Citation/CS1/styles.css has no content."MariaDB/server/blob/10.2/BUILD/SETUP.sh". MariaDB repository. MariaDB Foundation. Retrieved 2017-10-24.
  17. ^ Page Module:Citation/CS1/styles.css has no content."php/php-src/tree/master/ext/readline". PHP repository. The PHP Group. Retrieved 2017-10-24.
  18. ^ Page Module:Citation/CS1/styles.css has no content.Sanfilippo, Salvatore (10 May 2020). "antirez/linenoise". GitHub.
  19. ^ Page Module:Citation/CS1/styles.css has no content."The MongoDB Database". GitHub. Retrieved 23 March 2025.
  20. ^ Page Module:Citation/CS1/styles.css has no content."Redis". GitHub. Retrieved 23 March 2025.
  21. ^ Page Module:Citation/CS1/styles.css has no content."Android core". Google Git. 25 May 2010.
  22. ^ Page Module:Citation/CS1/styles.css has no content."Android's shell and utilities". Google Git.
  23. ^ Page Module:Citation/CS1/styles.css has no content."Applications and libraries". Haskell wiki. haskell.org. Retrieved 2017-10-24.
  24. ^ Page Module:Citation/CS1/styles.css has no content.Judah Jacobson. "judah/haskeline: A Haskell library for line input in command-line programs". Haskeline repository. Retrieved 2017-10-24.
  25. ^ Page Module:Citation/CS1/styles.css has no content."PowerShell/PSReadLine: A bash inspired readline implementation for PowerShell". PSReadLine repository. Retrieved 2023-12-20.
  26. ^ Page Module:Citation/CS1/styles.css has no content."Module: Readline (Ruby 3.2)".
  27. ^ Page Module:Citation/CS1/styles.css has no content."PHP: Readline - Manual". www.php.net. Retrieved 30 April 2025.

Lua error in mw.title.lua at line 404: bad argument #2 to 'title.new' (unrecognized namespace name 'Portal').

Lua error in package.lua at line 80: module 'Module:Navbox/configuration' not found.