私のスクリプト(nemo.actionを介して実行)には、エラーが発生したときにユーザーに停止するか続行するかを尋ねるzenithポップアップを使用するデバッグ機能があります。ただし、これがループ内で発生した場合、exit
スクリプトのコマンドは完全に無視される可能性があります。
とにかくスクリプトを完全に停止するには強制終了する方法はありませんか? ドードーのように死にたい! 本人が直接殺さなければならないのに…
これは私のデバッグの一部です。
44:57.198 • Stopped while renaming file/directory - it failed
44:57.199 • Error triggered, issue:
44:57.201 • Stopped while renaming file/directory.\nSee debug log for more info...
45:20.563 • Stopping the script by user request due error. ()
^^^ this line gets written to the log when the user choose to exit
vvv but it continues to run the script until a new error occurs
45:20.564 • Could not find ‘/temp/sani.txt‘ Have no value to assign to $jdir0
45:20.566 • Error triggered, issue:
45:20.567 • Could not find ‘/temp/sani.txt‘ Have no value to assign to $jdir0
45:24.670 • Stopping the script by user request due error. ()
^^^ and when pressing stop here, the script will halt..
これは同じエラー関数がトリガーされます。
jerror () {
enl
jdbugen "Error triggered, issue:\n\n"
jdbug "$@"
debuglogread=$(tail -10 "$debuglog")
zenity --question --text="($jdec)Error Triggered\nIssue:\n\n ‘$@‘\n\n$debuglogread\n\nContinue?" --width=400 --height=200
jdec=$?
if [ "$jdec" != 0 ]
then
jdbug "Stopping the script by user request due error. ($jdeck)"
exit 1
else
jdbug "User choose to continue the script"
fi
enl
}
スクリプトのこの部分は関数を呼び出します。
mv -f -v "$item" "$path/$name" &>> $debuglog # Rename
jok=$?
if [ $jok -ne 0 ]
then
jdbug "Stopped while renaming file/directory - it failed"
jerror "Stopped while renaming file/directory.\nSee debug log for more info..."
fi
ベストアンサー1
これは簡単ではなく、終了要求をファイルに保存して解決しました。
文字列を追加してprintf "%d" "1" > "/tmp/exitcode.dat"
値1を一時ファイルに保存します。
printf "%d" "1" > "/tmp/exitcode.dat" # Storing the exit code
exit 1 # Will break of of the loop
ループ後」完璧「コマンドを実行したら、ファイルをもう一度読む必要があります。
if [[ -f "/tmp/exitcode.dat" ]]
then
jexit="$(</tmp/exitcode.dat)" # Read the stored code
rm "/tmp/exitcode.dat" # Clean up and remove the file
if [ $jexit eq 1 ]; then exit 1; # Check if exit code is 1
fi
短いコードはファイルを生成することです。
touch "/tmp/exitcode.dat" # Create the file
exit 1 # Exit the loop
そしてその後完璧注文する
if [[ -f "/tmp/exitcode.dat" ]]; Then # See if the file exists
rm "/tmp/exitcode.dat" # Cleanup
exit 1 # Exit the script
fi