Fill empty string in array through Dialog Form

54 Views Asked by At

I need to make a little search form to find some titles in a db. I use dialog form from bash. The problem is that i can't get empty string when the form's field is not filled.

function searchEngine() { 

    exec 3>&1
        "ENGINE=($(dialog --clear --ok-label "Submit" \
          --title "Search Engine" \
          --form "Search" \
        15 50 0 \
        "1 :" 1 1   "${ENGINE[0]} " 1 20 30 0 \
        "2 :"    2 1    "${ENGINE[1]} " 2 20 30 0 \
        "3 :"    3 1    "${ENGINE[2]} " 3 20 30 0 \
        "4 :"     4 1   "${ENGINE[3]} " 4 30 20 0 \
    2>&1 1>&3))"
    
    exec 3>&-

}

echo "${ENGINE[*]}"

If 3 and 2 is not filled, ENGINE[0]=smthg ENGINE[1]=smthg ${#ENGINE[@]}=2 I need empty string for field not filled. Thanks in advance

1

There are 1 best solutions below

1
On

Add this at the bottom of your function:

for (( i=0; i<=3; i++ )); do
    ENGINE[i]="${ENGINE[i]}"
done

Change function searchEngine() { to just searchEngine() { by the way as adding that superfluous function keyword just makes it non-portable to other shells.