Difference between revisions of "Applications/Readline"
From HPC
(Created page with "__TOC__ ==Application Details== *Description: *Version: readline *Module: readline/6.3 *Licence: GNU ==Usage Examples== ===Module=== <pre style="background-color: #000000;...") |
m |
||
Line 1: | Line 1: | ||
__TOC__ | __TOC__ | ||
==Application Details== | ==Application Details== | ||
− | *Description: | + | *Description: Readline is a software library that provides line-editing and history capabilities for interactive programs with a command-line interface, such as Bash. |
*Version: readline | *Version: readline | ||
*Module: readline/6.3 | *Module: readline/6.3 |
Revision as of 14:09, 27 March 2017
Contents
Application Details
- Description: Readline is a software library that provides line-editing and history capabilities for interactive programs with a command-line interface, such as Bash.
- Version: readline
- Module: readline/6.3
- Licence: GNU
Usage Examples
Module
[username@login01 ~]$ module add readline/6.3
Compilation
readline is a library for use either with a compiled binary that requires it, or it could be required at compilation time also.
The following code is in C and must be linked against the readline library by passing a -lreadline flag to the compiler:
#include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <readline/readline.h> #include <readline/history.h> int main() { char* input, shell_prompt[100]; // Configure readline to auto-complete paths when the tab key is hit. rl_bind_key('\t', rl_complete); for(;;) { // Create prompt string from user name and current working directory. snprintf(shell_prompt, sizeof(shell_prompt), "%s:%s $ ", getenv("USER"), getcwd(NULL, 1024)); // Display prompt and read input (NB: input must be freed after use)... input = readline(shell_prompt); // Check for EOF. if (!input) break; // Add input to history. add_history(input); // Do stuff... // Free input. free(input); } return 0; }