I'm trying to use a for loop to create functions for choosing passwords in my Arch install script (based on easy-arch) using the following code (which uses this se answer for repeating prompts and this one for adding newlines to read):
#!/bin/bash
errEcho() { echo -e "${BOLD}${BRED}[ ${BBLUE}•${BRED} ] $1${RESET}"; }
for type in encrypt user root; do
pick_${type}pass() {
read -rsp "Enter $type password: " ${type}pass
read -rsp $'\nVerify password: ' ${type}pass2
echo
if [ "$typepass" != "$typepass2" ]; then
errEcho "Passwords don't match."
return 1
fi
return 0
}
done
until pick_userpass; do : ; done
When this is run I get the following errors (last line is spammed until script gets terminated):
./looptest.sh: line 3: `pick_${type}pass': not a valid identifier
./looptest.sh: line 3: `pick_${type}pass': not a valid identifier
./looptest.sh: line 3: `pick_${type}pass': not a valid identifier
./looptest.sh: line 15: pick_userpass: command not found
Does anyone know how a solution to this?