Leonardo Da Vinci
Leonardo Da Vinci

Reputation: 65

whiptail/dialog dynamic arguments

I want to construct a dynamic user friendly menu. I got stuck and found this answer

So, the question is pretty simple: why isn't it working?

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)

The current value of BOX="/bin/whiptail" , it's divided dynamically between whiptail and dialog. These prints were my attempt to debug. Here is the log:

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

The funniest part is that if I copy the line:

(/bin/whiptail --title "NLF Project builder" --menu "Choose the project" 10 30 2 \ "1" "MyProject" 3>&1 1>&2 2>&3)

from the prints, add a $ at the beginning and type it into the shell directly, it works .-. Just like the scipt does... supposedly... ^^"

Upvotes: 0

Views: 1724

Answers (1)

Leonardo Da Vinci
Leonardo Da Vinci

Reputation: 65

From this answer, that I found Thanks to Cyrus comment up there, I added set -x in my script and debuged. Here is the corret piece of code:

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)

Upvotes: 1

Related Questions