I'm going to guess that the reason you're using a 12+ year old version of Bash is that you must be trying to get this to work in modern OSX, which for some reason still ships Bash 3.2.57. For reference, Ubuntu 10.04 (released 2010-04-29) had Bash 4.1.5(1) cite.
The answer is probably going to be that -- for a lot of shell features -- your Bash version is simply too old to support this. You'll have to either rely on an external program, a workaround, or be content with what the old version supports.
Your Options
Note: I added -r to read (i.e. don't treat \ specially) because shellcheck complains about this.
Use #!/usr/bin/env bash as your script's bangline to bypass the default OSX shell (requires homebrew).
Do without it:
name=Alex
read -r -e -p "Please enter your name [$name]: " input
name=${input:-$name}
- Test Bash version before using
-i:
name=Alex
if [[ ${BASH_VERSINFO[0]} -ge 4 ]]; then
# We have a version of Bash that supports "read -i"
read -r -e -i "$name" -p 'Please enter your name: ' input
else
# Older version of Bash
read -r -e -p "Please enter your name [$name]: " input
fi
# Proceed as normal
name=${input:-$name}