bash select menu get index
bash, select, shell
Solution
You don't need to check which value is selected; you can simply use it. The only thing you do want to check against is `master`, which is simple to do.
select result in master $(list_last_ten_bfgminer_tags)
do
if [[ $result = master ]]; then
echo "continue installing master"
elif [[ -z "$result" ]]; then
continue
else
echo "switching to tag ${result}"
cd ${BFGMINER_INSTALL_PATH}
git checkout ${result}
fi
break
done
Problem
example ``` #!/bin/bash INSTALL_PATH="/usr/local" BFGMINER_INSTALL_PATH="${INSTALL_PATH}/bfgminer" BFGMINER_REPO="https://github.com/luke-jr/bfgminer.git" list_last_ten_bfgminer_tags () { cd ${BFGMINER_INSTALL_PATH} git for-each-ref --format="%(refname)" --sort=-taggerdate --count=10 refs/tags | cut -c 6- } clone_bfgminer () { cd ${INSTALL_PATH} git clone ${BFGMINER_REPO} ${BFGMINER_INSTALL_PATH} } echo "select number to switch tag or n to continue" select result in master $(list_last_ten_bfgminer_tags) do # HOW DO I CHECK THE INDEX??????? <================================= QUESTION if [[ ${result} == [0-9] && ${result} < 11 && ${result} > 0 ]] then echo "switching to tag ${result}" cd ${BFGMINER_INSTALL_PATH} git checkout ${result} else echo "continue installing master" fi break done ``` So if the user enters 1, the case statement checks for the match on the text, how can I match on 1 instead?