我真的不知道这叫什么,所以是的,基本上我想让用户只选择显示的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

linux - 允许用户仅选择一组显示的ID-LMLPHP

最佳答案

您可以尝试使用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

10-06 05:50