Re: gtkdialog again, the other way around this time – how to use bash variables in dialog?

Johnny Rosenberg gurus.knugum at gmail.com
Sun Apr 21 06:20:23 UTC 2013


2013/4/21 Johnny Rosenberg <gurus.knugum at gmail.com>:
> Here is some nonsense code that I'm trying to make work:
>
> #!/bin/bash
>
> #--- Define some variables -----------------------------------------------------
> RosenTagDir="${HOME}/bin/RosenTagg"
> InstrumentsList="${RosenTagDir}/Lists/Instruments"
> MusiciansList="${RosenTagDir}/Lists/Musicians"
> #-------------------------------------------------------------------------------
>
>
> #--- Define and open the dialogue ----------------------------------------------
> export MainDialog='
>     <vbox>
>         <hbox>
>             <text>
>                 <label>Instrument:</label>
>             </text>
>             <comboboxentry>
>                 <default>Välj musikinstrument</default>
>                 <variable>Instrument</variable>
>                 <input file>$InstrumentsList</input>
>             </comboboxentry>
>             <text>
>                 <label>Utövare:</label>
>             </text>
>             <comboboxentry>
>                 <default>Välj utövare</default>
>                 <variable>Musician</variable>
>                 <input file>$MusiciansList</input>
>             </comboboxentry>
>         </hbox>
>         <hbox>
>             <button ok></button>
>             <button cancel></button>
>         </hbox>
>     </vbox>'
> gtkdialog --program MainDialog
> #-------------------------------------------------------------------------------
>
> The problem is that $InstrumentsList and $MusiciansList doesn't
> expand, and whatever I tried I failed.
>
> MainDialog is just a variable, right? But how do I make bash variables expand?
> I have tried to fiddle with eval with no luck, for instance:
>
> $ echo $MainDialog
> <vbox> <hbox> <text> <label>Instrument:</label> </text>
> <comboboxentry> <default>Välj musikinstrument</default>
> <variable>Instrument</variable> <input file>$InstrumentsList</input>
> </comboboxentry> <text> <label>Utövare:</label> </text>
> <comboboxentry> <default>Välj utövare</default>
> <variable>Musician</variable> <input file>$MusiciansList</input>
> </comboboxentry> </hbox> <hbox> <button ok></button> <button
> cancel></button> </hbox> </vbox>
> $ eval echo $MainDialog
> bash: syntaxfel nära den oväntade symbolen "<"
> $
>
> (The error message, which is in Swedish, means something like ”syntax
> error near the unexpected symbol ”<”.)
> So obviously (?) I need a way to expand the variables but nothing
> else. Unfortunately I am a bit out of ideas, which is maybe not so
> strange considering that I'm not only a gtkdialog beginner; I'm a bash
> beginner as well, even though I learned a lot last years…
>
>
> Johnny Rosenberg


So I guess it's impossible, right (unless I write a separate program,
perhaps in C, that does the work for me)?
That's too bad. Of course I can type the whole path in the dialogue
definition, but I thought that since I have it in a variable anyway, I
could use that, but that was probably too good to be true, so now I
need to edit the path twice when I move the file. That sounds like
”bad programming”…


Johnny Rosenberg




More information about the ubuntu-users mailing list