francesc
francesc

Reputation: 343

bash inject escape sequences to read

I'm trying to do the following:

...$ left=$'\e[D'
...$ read -e -i "prompt${left}" line

I'd like to get prompt with cursor on t, but I get:

prompt^[[D

any ideas? Seems as if I cannot binding keystrokes with -i option

Upvotes: 0

Views: 86

Answers (2)

Philippe
Philippe

Reputation: 26447

On the command line, we can bind the read command to a function key :

bind '"'$(tput kf5)$'":"read -e -i prompt\n\e[D"'

You press F5 to run read

Upvotes: 0

KamilCuk
KamilCuk

Reputation: 140940

Just echo it.

echo -n "prompt${left}"
read -r line

Upvotes: 1

Related Questions