Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Get Input From Terminal With Prompt, History, Line Editor

DZone's Guide to

Get Input From Terminal With Prompt, History, Line Editor

·
Free Resource
Using this script you will be able to read user input using readline goodies but without need to manually program readline library. Just save it under e.g. /usr/local/bin/getline, and then call like:
getline {prompt} {historydir}.

for example:
getline "input> " "/tmp"

You can for example call this script from php using popen(). This way php doesn't have to include readline module, and you can do shell stuff not inside php, but using shell code, which is more natural and comfortable way to do it.


#!/bin/bash -f
history -r "$2/.getline_history"
LINE=""
read -re -p "$1" LINE
history -s "$LINE"
history -w "$2/.getline_history"
echo $LINE

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}