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を使用して1行ずつ解析する標準出力にデータをダンプするbconsoleバイナリ実行可能ファイル。list media

問題は、最後のreadステートメントがユーザーの入力を受け入れないことです。プロンプトが表示され、"[rescan]/exit: "入力できますが、このボタンを押すと、プロンプトなしで再入力するように求められます"[rescan]/exit: "。エラーはありません。最後のステートメントに添付されているため、スクリプトを終了するにはCTRL-Cを押す必要がありますread。標準入力をリダイレクトする方法についてのすべてを読んで、プログラムが完了するまで読んでそれを利用する方法はありませんが、私のwhile loop問題は回避策や修正がないようです。

頑張ったこのソリューション約4つがありましたが、それらのどれもreadユーザー入力の最後の説明を受け入れることにもう近づいていませんでした。

私はそれがreadwhileループを介してまだリダイレクトしていると仮定していますが、ループが完了すると解放されると思います。これを機能させる魔法の弾丸は何ですか?

ベストアンサー1

おすすめ記事