I would like to show user friendly whiptail menu.

My goal in whiptail is this:


I have array consist of:

Choice1 Choice2 Choice3 Choice4

I run array through loop for like this:

for value in ${value[@]}
    echo "$value"

I could not add whiptail inside echo because I get 4 another menus.

I tried script like this:

$val=$(whiptail --title "xx" --menu "choose" 16 78 10
for value in ${value[@]}
    echo "$value"
3>&1 1>&2 2>&3)

After run above mentioned script my shell looks horrible.

shell after script:

enter image description here

Is there anybody who solve my problem?


There is several errors in your script, e.g. you should not give the loop iterator the same name as array itself. However your don't need any loop for this task, just put all array elements at once with special array index @:

value=(Choice1 "" Choice2 "" Choice3 "" Choice4 "")
whiptail --title "xx" --menu "choose" 16 78 10 "${value[@]}"

Notice empty string inside quotes "" - this is description required by whiptail menu option, without that you would treat Choice and Choice4 as description:

Choice1 Choice2
Choice3 Choice4

what is probably not what you want.

  • Thank you for your answer. But this is what I wanted to avoid. I have got another solution. Do you know how to duplicate records in array? I am gonna run through whiptail as you described and set --notag. – Michal N. Jan 1 '16 at 21:41
  • @MichalN. What do you mean by "duplicate"? You want repeat all elements one more time in the same order or add neighbor to each element? – jimmij Jan 1 '16 at 21:47
  • @jimmj Yes, all elements in the same order. – Michal N. Jan 1 '16 at 21:48
  • @MichalN. new=("${value[@]}" "${value[@]}") – jimmij Jan 1 '16 at 21:57
  • @jimmj I did not express myself corectly - my mistake. I want output duplicated output like this: Choice1 Choice1 Choice2 Choice2 Choice3 Choice3 Choice4 Choice4 instead Choice1 Choice2 Choice3 Choice4 Choice1 Choice2 Choice3 Choice4 – Michal N. Jan 2 '16 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.