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 13:23:11 UTC 2013
2013/4/21 Nils Kassube <kassube at gmx.net>:
> Johnny Rosenberg wrote:
>> > Anyway, so far, so good, but the next step is to keep the dialogue
>> > in a separate file, like this (file name stored in
>> > ${DialogFolder}/musician-dialogue.xml
> [...]
>> > <input file>$InstrumentsList</input>
> [...]
>> > <input file>$MusiciansList</input>
>
>> > Now, in the script, I have the following lines:
>
>> > export MainDialog=$(<${DialogFolder}/musician-dialogue.xml)
>> > gtkdialog --program MainDialog
>
>> > Now I end up with the same problem again; the Bash variables do not
>> > expand. I tried a few different combinations of double quotes on
>> > the export MainDialog=$(<${DialogFolder}/musician-dialogue.xml)
>> > line with no luck.
>
> It doesn't work like this, no matter what quotes you use. The assignment
> reads the contents of the file without variable expansion. But you could
> replace the variables afterwards like this (untested):
>
> MainDialog=$(<${DialogFolder}/musician-dialogue.xml)
> MainDialog="${MainDialog/\$InstrumentsList/$InstrumentsList}"
> MainDialog="${MainDialog/\$MusiciansList/$MusiciansList}"
> export MainDialog
>
>
> Nils
Thanks, that works!
I was actually thinking something almost similar, using sed instead,
but this looks more elegant, and I have seen that people seems to say
that it's better to use the shell built-in stuff rather than to invoke
external programs or commands.
I guess another thing that could also work (but I like this one
better) is to redesign the Dialogue entirely, like this:
MainDialog="
<vbox>
…
…
</vbox>"
gtkdialog --program MainDialog
Then just run the file from the main file.
Or making the dialogue thing a function in the dialogue file.
But as I said, I like this way better (which not necessarily means
that it IS better; I'm probably not the right person to say that…)
Thanks again!
Johnny Rosenberg
More information about the ubuntu-users
mailing list