在 「Linux Mint的16佩特拉」 我鍵入此命令:Zenity - 不同的返回值
zenity --list --column "test" a b c
我選擇項目 'A',那麼returnning值是隨機
a or a|a
怎麼辦你解釋一下嗎?這是一個zenity錯誤嗎? 如何獲得'a'?
問候。
在 「Linux Mint的16佩特拉」 我鍵入此命令:Zenity - 不同的返回值
zenity --list --column "test" a b c
我選擇項目 'A',那麼returnning值是隨機
a or a|a
怎麼辦你解釋一下嗎?這是一個zenity錯誤嗎? 如何獲得'a'?
問候。
當您使用鼠標雙擊(或使用鍵盤上的回車鍵)來選擇「a」時,值爲「a | a」。當您選擇它並按下「確定」時,該值爲「a」。 我不知道爲什麼。
簡單的解決方法可能是:
TMP=$(zenity --list --column "test" a b c) # Save the returned value in TMP
VAL=${TMP:0:1} # Keep the first character of TMP and put it in VAL
echo $VAL # VAL = "a", "b" or "c"
因此,如果值不止一個字符,我們必須分割:'TMP = $(zenity --list --column「test」item1 another and thelast); #將返回值保存在TMP中' 'IFS ='|'讀-a數組<<<「$ TMP」; #分割| |如果存在' 'VAL =「$ {array [0]}」;' 'echo $ VAL;' – Jeff
是的,這是一個簡單的解決方案來保持正確的結果。但我真的不知道爲什麼Zenity會返回不同的結果... –
這是一個非常惱人的錯誤。今年也不是第一次。搜索結果「 - 文本」請選擇要打開的文件或目錄:「 - 請選擇文件或目錄打開:」 - 選擇文件或目錄打開:「 - 寬800 --height 600 --column 「文件」)
打開= $(回聲$開放|切-d 「|」 -f2)
打印每值在|
分開的列表中:zenity --list --print-column=ALL
(...)並獲取整個選定的行。
剛剛發現:select a + keyboard enter returns a | a。選擇一個+有效的按鈕返回一個。那麼如何在兩種情況下獲得'a'? – Jeff