Difference between revisions of "Applications/Readline"
From HPC
m (→Navigation) |
|||
Line 67: | Line 67: | ||
[http://www.boost.org/ http://www.boost.org/] | [http://www.boost.org/ http://www.boost.org/] | ||
− | + | {{Modulepagenav}} | |
− | |||
− | |||
− | |||
− | |||
− |
Revision as of 10:57, 16 November 2022
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 and readline/7.0
- Licence: GNU
Usage Examples
Module
[username@login01 ~]$ module add readline/7.0
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; }