treetop treetop - 1 year ago 82
Linux Question

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.



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


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

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

$opt) echo you have chosen $file ;;


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.

Answer Source

You need to break the execution:

$opt) echo you have chosen $file


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download