我真的不知道这叫什么所以是的,基本上我想让用户只选择显示的 ID(见图)。我正在考虑拥有一个变量并将这些数字保存为数组,但我不知道,因为我仍在学习 bash 脚本。谢谢!
我的脚本是这样的
read -p "Select accessory category below."
mysql -D snipeit -e "SELECT id AS ID, name AS Name FROM categories WHERE category_type='accessory';"
read -p "Accessory category: " accessoryCateg
if *(allow only 4, 5, 7, 8, 9, 10, 11, 12, 13, 14 to be selected)*
*inserts data into database*
else echo "Try again!"
fi
最佳答案
你可以尝试使用select
命令:
echo "Select accessory category below."
sample1=`mysql -D snipeit -e "SELECT id AS ID FROM categories WHERE category_type='accessory';"`
options=(`echo $sample1 | cut -d ' ' -f2-`)
PS3="Please select a category: "
select accessoryCateg in "${options[@]}"
do
echo "selected $accessoryCateg"
#inserts data into database
break;
done
关于linux - 允许用户仅选择一组显示的 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38367444/