linux - 防止 case 语句不断要求输入,以便我可以执行后续命令

标签 linux bash case

我有以下代码,其中包含一个 case 语句。

#!/bin/bash

ltfs=/usr/local/bin/ltfs
INDEX_FILE=/opt/LTO6_Extract/index.txt

sudo umount /mnt/ltfs

 echo "Please push tape into drive and once the light stops flashing press ENTER"
        read enterme
        echo -n "Mounting the tape....."

        sudo $ltfs -o devname=/dev/nst1 /mnt/ltfs

# We need the index file to get list and names of tape content

ls -R /mnt/ltfs/ | grep \.mxf$ > $INDEX_FILE

clear


PS3='Please enter your choice: '
readarray -t options < $INDEX_FILE

select opt in "${options[@]}"
do
IFS=  read file <<< $opt
case  $opt  in


    $opt) echo you have chosen $file ;;


esac
done

echo $file | sed 's/.mxf//g'

我的问题是,一旦从选项菜单中选择了一个文件,它随后不断要求我输入更多选择,但我只想输入一个然后执行后续命令(在这种情况下,后续命令位于底部(echo $file | sed 's/.mxf//g')。 我确定这很简单,但我似乎无法弄清楚它是什么。

最佳答案

您需要中断执行:

$opt) echo you have chosen $file
      break;;

Documentation

关于linux - 防止 case 语句不断要求输入,以便我可以执行后续命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37573043/

相关文章:

regex - linux - 如何将 sed 与正则表达式一起使用

c - 在 Linux 中通过串口通信发送十六进制数据

node.js - 使用 NVM 设置 Node 版本或安装(如果不可用)。

mysql - 无法一致地设置变量

mysql - SQL:每个 ID 创建超过 1 个值的查询

linux - 检查 SSH 隧道是否已启动并正在运行

mysql - Debian 10 MariaDB 'Can' t 通过套接字 '/var/run/mysqld/mysqld.sock' (2)' 连接到本地 MySQL 服务器

arrays - 我可以使用 read 内置函数将换行符分隔的字符串放入数组中吗?

python - 在 Python 中定期获取 bash 命令的输出

SQL:在已分组的表上使用 CASE