Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to present editable input to a user with BASH and ZSH?

I need to accept user input within a shell script that can run both in BASH and ZSH. I'm accustomed to using readline in other languages, but this doesn't seem to be a viable option in shell scripting.

An example prompt might be:

Please enter the value> 1234_

How can I present a user with editable input that has a default value that can be edited (backspaced) that's compatible with both shells?

like image 418
ylluminate Avatar asked Dec 30 '25 10:12

ylluminate


1 Answers

User @cyrus mentioned in the comments, but is better directly as an answer instead:

read -e -p 'Please enter the value> ' -i '1234' myvar
echo $myvar

results in an editable default of 1234

Please enter the value> 1234
1234
like image 74
Catskul Avatar answered Jan 01 '26 04:01

Catskul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!