我想构建一个动态的用户友好菜单。我被卡住了,找到了这个答案
所以,问题很简单:为什么它不起作用?
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 和dialog 之间动态划分。这些打印是我调试的尝试。这是日志:
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 "NLF Project builder" --menu "Choose the project" 10 30 2 \ "1" "MyProject" 3>&1 1>&2 2>&3)
从打印中,在开头添加一个 $ 并直接将其输入到 shell 中,它可以工作.-。就像 scipt 所做的那样……据说……^^”