whiptail / dialog动态参数

时间:2016-06-19 15:06:39

标签: bash shell dialog whiptail

我想构建一个动态的用户友好菜单。我卡住了,找到了this answer

所以,问题很简单:为什么它不起作用?

COUNT=1
AUX=0;
for proj in $PROJECTPATH/*; do
    if ! [ -d $proj ]; then
        echo "$proj is not a directory, what the hell is it doing here?"
        rm -v -f $proj
    else
        proj=${proj:${#PROJECTPATH}}
        STR[AUX]="\\ \""${COUNT}"\" \""${proj:1}"\" "
        COUNT+=1
        AUX+=1
    fi
done
printf "${STR[@]}\n"
printf "$BOX\n"
printf "($BOX --title \"NLF Project builder\" --menu \"Choose the project\" 10 30 2 ${STR[@]} 3>&1 1>&2 2>&3)"
USERPROJECT=$($BOX --title \"NLF Project builder\" --menu \"Choose the project\" 10 30 2 ${STR[@]} 3>&1 1>&2 2>&3)

BOX的当前值=" / bin / whiptail" ,它在whiptail和对话之间动态划分。 这些打印是我尝试调试的。这是日志:

using /bin/whiptail...
\ "1" "MyProject" 
/bin/whiptail
(/bin/whiptail --title "NLF Project builder" --menu "Choose the project" 10 30 2 \ "1" "MyProject"  3>&1 1>&2 2>&3)
Box options: --msgbox <text> <height> <width> --yesno <text> <height> <width> --infobox <text> <height> <width> --inputbox <text> <height> <width> [init] --passwordbox <text> <height> <width> [init] --textbox <file> <height> <width> --menu <text> <height> <width> <listheight> [tag item] ... --checklist <text> <height> <width> <listheight> [tag item status]... --radiolist <text> <height> <width> <listheight> [tag item status]... --gauge <text> <height> <width> <percent> Options: (depend on box-option) --clear clear screen on exit --defaultno default no button --default-item <string> set default string --fb use full buttons --nocancel no cancel button --yes-button <text> set text of yes button --no-button <text> set text of no button --ok-button <text> set text of ok button --cancel-button <text> set text of cancel button --noitem display tags only --separate-output output one line at a time --output-fd <fd> output to fd, not stdout --title <title> display title --backtitle <backtitle> display backtitle --scrolltext force vertical scrollbars --topleft put window in top-left corner

最有趣的部分是,如果我复制该行:

  

(/ bin / whiptail --title&#34; NLF Project builder&#34; --menu&#34;选择   项目&#34; 10 30 2&#34; 1&#34; &#34; MyProject的&#34; 3&gt;&amp; 1&gt;&amp; 2 2&gt;&amp; 3)

从打印件中,在开头添加$并直接在shell中输入它,它可以工作.-。就像scipt那样......据说...... ^^&#34;

1 个答案:

答案 0 :(得分:0)

来自this answer,我发现感谢Cyrus在那里评论,我在我的脚本中添加了 set -x 并进行了调试。这是相关的代码:

COUNT=1
AUX=0;
for proj in $PROJECTPATH/*; do
    if ! [ -d $proj ]; then
        echo "$proj is not a directory, what the hell is it doing here?"
        rm -v -f $proj
    else
        proj=${proj:${#PROJECTPATH}}
        STR[AUX]="${COUNT} ${proj:1}"
        COUNT+=1
        AUX+=1
    fi
done
USERPROJECT=$($BOX --title "NLF Project builder" --menu "Choose the project" 10 30 2 ${STR[@]} 3>&1 1>&2 2>&3)