I use Bash’s read -e -i to show an existing value that someone can edit, but macOS’s bundled Bash 3.2 does not support -i. Is there a portable workaround, or a practical alternative?
How can I prefill editable input in Bash 3.2 on macOS?
Answers
The simplest portable option is to show the default in the prompt, then use it if the user just presses Enter. It does not put the value into the input line for editing, but it works with Bash 3.2:
default=$bslprintf 'Bsl [%s]: ' "$default"IFS= read -r bslbsl=${bsl:-$default}
Repeat that pattern for each value. The distinction matters: this supplies a default, but it is not true prefilled, editable input.
Reply to this answer
If you specifically need the existing text visible in the editable line, the built-in Bash 3.2 read interface does not offer the same -i option. One way around that is to use a newer Bash on macOS, if you can make that a requirement for the script. Otherwise, displaying the default in brackets is the straightforward fallback.
Reply to this answer
Add your answer
Answers are reviewed before publication.
quiet_switch:
That makes sense. I can decide whether showing the default in the prompt is enough, or document a newer Bash requirement.