I need to set a default value (y) when the user hits enter in read
validate() {
local validated=false
while [ "$validated" != "true" ]; do
read -p "$1 " $2
$2=${2:-y}
if [[ "$2" == "y" || "$2" == "n" ]]; then
validated=true
fi
done
}
When I run this function with validate "text" test and skip the read with enter, the error test=test: command not found appears.
How can I use the substitution with function arguments?