Reputation: 5086
I have the following script (called ./script
), which I want to run with $( ./script )
because the result should set some environment variable. Strangely the zenity dialog is displayed twice before the script terminates when I run it in $( )
, while it is only displayed once if I run it as is.
#!/bin/bash
export select=`zenity --list --column=select "option1" "option2"`
echo "export SELECTION_VAR=$select"
Can anybody explain, why it is executed twice and how I can avoid this?
Upvotes: 0
Views: 100
Reputation: 10264
Since script
is trying to affect the parent environment, you need to eval
its resulting output. This pattern is common, and you can find a similar case done by the keychain
tool. If you invoke keychain
, it spits out to stdout an eval
-able statement like:
SSH_AGENT_PID=1234; export SSH_AGENT_PID;
So for your case, you’d invoke script
with:
% eval $(./script) # choose option2
% echo $SELECTION_VAR
option2
Also, you shouldn’t need the export
on your select=
line.
Upvotes: 1