Skip to content
Advertisement

Prevent case statement from continually asking for input so that I can carry out subsequent commands

I have the following code which includes a case statement.

#!/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'

My problem is that once a file is selected from the option menu, it subsequently keeps asking me to input further choices, but I only want to input one then carry out out the subsequent commands (in this case the subsequent command is at the bottom (echo $file | sed 's/.mxf//g'). I’m sure this is something simple but I can’t seem to work out what it is.

Advertisement

Answer

You need to break the execution:

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

Documentation

Advertisement