gtkdialog – variables

Johnny Rosenberg gurus.knugum at gmail.com
Wed Apr 17 18:39:34 UTC 2013


I'm experimenting a bit (at level ”beginner”) with gtkdialog and there
is one thing that I can't figure out.

I can use variables in dialogues, but I can't use those variables
”outside” the dialogue in my script.

Here's an example, in which the user pick a car and a colour. Of
course I want to set two variables with the user's choice.

First create two text files, one of them with car brands and the other
one with colours:
Cars:
Citroën
Mazda
Škoda
Volvo

Colours:
Black
Brown
Red
Orange
Yellow
Green
Blue
Violette
Gray
White

Now the script:
#!/bin/bash
export MainDialog='
    <vbox>
        <hbox>
            <text>
                <label>Car:</label>
            </text>
            <comboboxentry>
                <default>Select a bloody car</default>
                <variable>SelectedCar</variable>
                <input file>Cars</input>
            <sensitive>true</sensitive>
            </comboboxentry>
            <text>
                <label>Colour:</label>
            </text>
            <comboboxentry>
                <default>Are you going to select a colour or what?</default>
                <variable>SelectedColour</variable>
                <input file>Colours</input>
            </comboboxentry>
        </hbox>
        <hbox>
            <button ok></button>
            <button cancel></button>
        </hbox>
    </vbox>'
gtkdialog --program=MainDialog
# ----------------------------------------------------------------------------------------------

Running this, selecting ”Citroën” and ”Black” and hitting OK gives the
following output (at standard out):
SelectedCar="Citroën"
SelectedColour="Black"
EXIT="OK"

However, when trying to use those variables in the Bash part of the
script, they do no longer exist:
#!/bin/bash
export MainDialog='
    <vbox>
        <hbox>
            <text>
                <label>Car:</label>
            </text>
            <comboboxentry>
                <default>Select a bloody car</default>
                <variable>SelectedCar</variable>
                <input file>Cars</input>
            <sensitive>true</sensitive>
            </comboboxentry>
            <text>
                <label>Colour:</label>
            </text>
            <comboboxentry>
                <default>Are you going to select a colour or what?</default>
                <variable>SelectedColour</variable>
                <input file>Colours</input>
            </comboboxentry>
        </hbox>
        <hbox>
            <button ok></button>
            <button cancel></button>
        </hbox>
    </vbox>'
gtkdialog --program=MainDialog

echo "Buy a ${SelectedColour} ${SelectedCar} today."
echo "Tomorrow it may be illegal."
# ----------------------------------------------------------------------------------------------

Both of those variables are empty, unfortunately.

I read as much of the documentation as I found about this, and I only
found this information:

Directives
Name: variable export="false"      Description: Variable name, not
exported to shell

Therefore I tried:
<variable export="true">SelectedCar</variable>

However, with no luck at all.

Any ideas, please?


Ubuntu 12.04
gtkdialog 0.8.3, compiled from source, see
http://code.google.com/p/gtkdialog/downloads/detail?name=gtkdialog-0.8.3.tar.gz&can=2&q=
That page also says: ”Added support for <variable
export="false">VARNAME</variable>”
That doesn't seem to be necessary, since the variable doesn't seem to
be exported anyway…


Johnny Rosenberg




More information about the ubuntu-users mailing list