2016-09-10 34 views
0

我有下面的代碼創建了一個對話框:xargs的覆蓋對話框的退出狀態

exec 3>&1 
    selection=$(echo " --backtitle \"Patches\" 
    --extra-button --extra-label \"See File List\" 
    --title \"Patches\" --clear --ok-label \"Create\" --cancel-label \"Exit\" 
    --menu \"Please select:\" $HEIGHT $WIDTH 25 $gridData" | 
    xargs dialog 2>&1 1>&3) 
    exit_status=$? 
    exec 3>&- 

對話框除了擁有好的一個額外的按鈕/取消對(雖然我已經給他們改名)。除非單擊額外的按鈕,否則它效果很好,在這種情況下$ exit_status具有與點擊取消按鈕相同的值(123)。有沒有一種方法可以讓對話的狀態沒有xargs干擾它?

+2

如果您嘗試一次創建多個對話框,則只能使用'xargs'。這裏沒有必要。 – chepner

回答

2

根據xargsman page

xargs exits with the following status: 
    0 if it succeeds 
    123 if any invocation of the command exited with status 1-125 
    124 if the command exited with status 255 
    125 if the command is killed by a signal 
    126 if the command cannot be run 
    127 if the command is not found 
    1 if some other error occurred. 

什麼是你想在這裏完成?我不明白你爲什麼在這種情況下需要xargs。你不是應該直接調用dialog,就像這樣:

dialog --backtitle Patches \ 
    --extra-button --extra-label "See File List" \ 
    --title Patches --clear --ok-label Create --cancel-label Exit \ 
    --menu "Please select:" $HEIGHT $WIDTH 25 "$gridData" 

這會工作,即使$gridData包含特殊字符(如"或空格)。

+0

對話框的退出狀態很重要,因爲這是確定單擊哪個按鈕的唯一方法 –

+2

@TichomirMitkov對不起,我想清楚。我的意思是,這裏不需要'xargs',只需直接調用'dialog'即可。 – redneb

+0

我需要它,因爲空白。 $ gridData包含用雙引號括起來的字段。 –