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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With