Having trouble passing double quotes to dialog

0

I'm working on a script for automating audio recording, using the 'dialog' command to create an interactive menu to appropriately name channels. I've got a list of the channel names in an array. I want the form itself to be blank, but I can't seem to pass the right parameters to dialog.

If I escape the quotes, the form appears as it should, but the quotes appear in the input area, If I don't escape the quotes, it results in a garbled mess, and if I echo the command to another file and execute it, it works exactly like I want. I need help figuring out how to get dialog to execute in that manner.

This is the code:

#!/bin/bash
declare -a CHANNELS
CHANNELS=(meet george jetson his boy elroy daughter judy)

channameiter ()
{
        for i in ${!CHANNELS[@]};
        do
                echo  -e "${CHANNELS[$i]}:" $((i + 1)) 1 \'\' $((i + 1)) 25 30 30 \
        done
}

dialog --form "Channels" 30 60 16 `channameiter`

and this is the code echoed to another file, and then executed, which runs correctly.

dialog --form Channels 30 60 16 meet: 1 1 "" 1 25 30 30 george: 2 1 "" 2 25 30 30 jetson: 3 1 "" 3 25 30 30 his: 4 1 "" 4 25 30 30 boy: 5 1 "" 5 25 30 30 elroy: 6 1 "" 6 25 30 30 daughter: 7 1 "" 7 25 30 30 judy: 8 1 "" 8 25 30 30

Any ideas?

Seth O'Bannion

Posted 2015-09-04T14:30:38.353

Reputation: 13

Answers

2

Here's one way of doing it, in which the array of command-line arguments is built up iteratively:

#!/bin/bash
args=(Channels 30 60 16)
i=0
for chan in meet george jetson his boy elroy daughter judy; do
   ((++i))
   args+=("$chan" $i 1 "" $i 25 30 30)
done
dialog --form "${args[@]}"

Of course, this could have used the same CHANNELS array and iteration technique as your original. (Personally, I think I would take the channel names from the command-line options to the script, in which case you could just write for chan; do.)

rici

Posted 2015-09-04T14:30:38.353

Reputation: 3 493