Bash
無法正確退出 bash 腳本
我在 bash 上做了一個腳本。
#!/bin/bash zen(){ mark=$(zenity --scale \ --text 'FREQUENCY' \ --value=$la \ --min-value=0\ --max-value=5000 \ --step=1) } la=500 echo "Script for shim. Regulary frequency" zen while [ true ] do case $? in 0) echo $mark la=$mark #zenity --notification --window-icon="info" --text="Thank you!" --timeout=1 zen ;; 1) # exit 1 # sl -e || break # break # return 1 ;; esac done echo "thanks for using!"
它工作正常,不包括出口點。# 站在我嘗試過的選項之前,每個選項都不允許正確退出此腳本,而不是“感謝使用!” 或者我在終端沒有得到任何東西:
This option is not available. Please see --help for all possible usages. This option is not available. Please see --help for all possible usages. This option is not available. Please see --help for all possible usages. This option is not available. Please see --help for all possible usages. This option is not available. Please see --help for all possible usages. This option is not available. Please see --help for all possible usages. This option is not available. Please see --help for all possible usages. This option is not available. Please see --help for all possible usages. This option is not available. Please see --help for all possible usages. This option is not available. Please see --help for all possible usages. This option is not available. Please see --help for all possible usages. This option is not available. Please see --help for all possible usages. ^XThis option is not available. Please see --help for all possible usages. This option is not available. Please see --help for all possible usages. This option is not available. Please see --help for all possible usages. This option is not available. Please see --help for all possible usages. .........................................
當我試圖退出腳本時,它看起來像是 zenity 的問題。我查看了這個錯誤,唯一合理的想法是升級 zenity,我已經這樣做了,但它沒有給我任何新的東西……
那麼我該如何解決它並正確地破壞這個腳本..?
我的作業系統是 Ubuntu Server 16.04
編輯
通過我的腳本,我想實現從 zenity 到使用者點擊“取消”的重複問題
$?
是最後執行的命令的退出狀態。在您的情況下,這就是[
命令(您使用它來測試true
字元串是否為非空作為while
循環的條件)。您幾乎不需要
$?
顯式使用。做就是了la=500 while mark=$(zenity --scale \ --text 'FREQUENCY' \ --value="$la" \ --min-value=0 \ --max-value=5000 \ --step=1) do echo "$mark" la=$mark done
或者簡單地說:
mark=500 while mark=$(zenity --scale \ --text 'FREQUENCY' \ --value="$mark" \ --min-value=0 \ --max-value=5000 \ --step=1) do echo "$mark" done