Bash에서 while 루프 후에 작업을 다시 읽는 방법

Bash에서 while 루프 후에 작업을 다시 읽는 방법
#!/bin/bash

echo "Export Tape(s):"
echo "---------------"

stdbuf -oL echo "list media" | bconsole | {

while IFS= read -r line
do
        line=$(echo ${line^^})

        if [[ "$line" == *"POOL"* ]] && [[ "$line" != *"DEFAULT"* ]] && [[ "$line" != *"FILE"* ]] && [[ "$line" != *"SCRATCH"* ]] && [[ "$line" != *"DUMMY"* ]]; then
                echo " "
                echo "$line" | awk '{print "["$2"]"}'
        fi

        
        if [[ "$line" == *"FULL"* ]]; then
                inChanger=$(echo "$line" | awk '{print $20}')

                if [[ "$inChanger" == 1 ]]; then
                        expiresIn=$(echo "$line" | awk '{print $31}')

                                if [[ "$expiresIn" != 0 ]]; then
                                         echo "$line" | awk '{print "   Date: "$28" Barcode: "$4}'
                                        ((tapesToExport++))
                                fi

                else
                        newElement1=$(echo "$line" | awk '{print $4}')

                                if [[ $newElement1 != VOL* ]] && [[ $expiresIn = 0 ]]; then
                                        newElement2=$(echo "$line" | awk '{print $28}')
                                        tapeBarcode+=( $newElement1 )
                                        tapeDate+=( $(date -d "$newElement2" +"%s") )
                                fi
                fi
        fi
done

IFS=$'\n' sorted=($(sort <<<"${tapeDate[*]}"))
unset IFS

sorted=( "${sorted[@]:0:$tapesToExport}" )

count=-1
for (( i=0; i<"${#tapeDate[@]}"; i++ )); do
        (( count++ ))

        if [[ "${sorted[$i]}" = "${tapeDate[$count]}" ]]; then
                arrayOfRequiredIndexes[$i]=$count
        else
                (( i-- ))
        fi

        if [[ "$i" = "$((tapesToExport-1))" ]]; then
                break
        fi

done

        if [[ "$tapesToExport" > 0 ]]; then
                echo " "
                echo -e "\e[1;37m╒═══════════════════════════════════════════════════════════════╕\e[0m"
                echo -e "\e[1;37m│       Populate the TAPES.XLS file with the tapes above.       │\e[0m"
                echo -e "\e[1;37m│           Print EXCEL file and attach to each tape.           │\e[0m"
                echo -e "\e[1;37m│                                                               │\e[0m"
                echo -e "\e[1;37m│         Replace the "$tapesToExport" tape(s) that you'll export above        │\e[0m"
                echo -e "\e[1;37m│                 with the "$tapesToExport" recommended below...               │\e[0m"
                echo -e "\e[1;37m╘═══════════════════════════════════════════════════════════════╛\e[0m"
                echo " "
                echo "Recommended Tapes to Import:"
                echo "----------------------------"

                for i in ${arrayOfRequiredIndexes[@]}; do
                        echo "Date: "$(date '+%Y-%m-%d' -d @${tapeDate[$i]})" Barcode: "${tapeBarcode[$i]}
                done
        else
                echo " "
                echo -e "\e[1;37mThere are no tapes to export.\e[0m"
                echo " "
                exit 1
        fi
}
                if [[ $? -eq 1 ]]; then
                    exit 0
                fi

                echo " "
                echo "When you are finished importing the tape(s),"
                echo "Type 'rescan' to issue a command for the tape"
                echo "library to rescan.  Or you can type 'exit' to"
                echo "terminate the program."

                while [[ "${userResponse}" != "exit" ]]; do
                        read -p "[rescan]/exit: " userResponse
                             if [[ "$userResponse" == "rescan" ]] || [[ -z "$userResponse" ]]; then
                                echo "update slots storage=TL2000-01 drive=0"
                             fi
                done

                                echo " "
                                echo -e "\e[2;37mDone!\e[0m"
                                echo " "

나는 이 게시물을 편집하고 완전한 맥락이 있도록 모든 코드를 배치했습니다. awk를 사용하여 한 줄씩 구문 분석하는 표준 출력에 데이터를 덤프하는 bconsole이진 실행 파일입니다 .list media

문제는 마지막 read문이 사용자의 입력을 받아들이지 않는다는 것입니다. 프롬프트가 표시되고 "[rescan]/exit: "입력할 수 있지만 이 버튼을 누르면 프롬프트 없이 다시 입력하라는 메시지가 표시됩니다 "[rescan]/exit: ". 오류가 없습니다. 마지막 명령문에 붙어 있기 때문에 스크립트를 종료하려면 CTRL-C를 눌러야 합니다 read. 표준 입력을 리디렉션하는 방법에 대한 모든 내용을 읽었으며 프로그램이 완료될 때까지 읽어서 이를 활용할 수 있는 방법이 없지만 내 while loop문제는 해결 방법이나 수정 사항이 없는 것 같습니다.

나는 노력했다이 솔루션약 4개가 더 있었지만 그 중 어느 것도 read사용자 입력의 마지막 설명을 받아들이는 데 더 이상 가까워지지 않았습니다.

나는 그것이 readwhile 루프를 통해 여전히 리디렉션 중이라고 가정하고 있지만 루프가 완료되면 해제될 것이라고 생각합니다. 이를 작동하게 만드는 마법의 총알은 무엇입니까?

관련 정보