我想构建一个动态的用户友好菜单。我被卡住了,找到了这个答案
那么,问题很简单:为什么不起作用?
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 "$BOXn"
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-标题" NLF Project Builder" - Menu"选择 项目" 10 30 2 " 1" myproject" 3>&amp; 1 1>&amp; 2 2>&amp; 3)
从印刷品开始,在开始时添加$,然后将其直接键入外壳,它起作用.-。就像scipt一样...据说... ^^"
从这个答案中,我对那里的Cyrus评论感到非常感谢,我在脚本中添加了 set -x 并进行了调试。这是corret的代码:
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)