#!/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
因此,如果用戶輸入1,case語句檢查比賽上的文字,我怎麼能匹配1呢?
相關的和非常有用:http://stackoverflow.com/a/226724/1983854 – fedorqui
@fedorqui謝謝,我已經看到了這一點之前,是一個偉大的職位,我想看看我是否能訪問按索引 –
bash選擇數組我不明白你的問題,如果價值被返回,你怎麼知道哪個答案被選中?你通常想要的是價值而不是索引,這是'select'的全部方便。 –