• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Exporting a variable to a variable in Bash?

screw3d

Diamond Member
I'm running Ubuntu Fiesty on my personal box, and to get around a problem described here: http://ubuntuforums.org/showthread.php?t=438639, I tried to do this in a shell script:


#!/bin/sh
export DBUS_SESSION_BUS_ADDRESS=`echo $DBUS_SESSION_BUS_ADDRESS` && rhythmbox-client --play-pause


The problem is that the echo statement in the backtick goes into the export, not the eval-ed value. I tried a few combinations of "sh -c ..." but nothing seemed to work. BTW I'm on bash.

Pointers?
 
You can't just have $DBUS_SESSION_BUS_ADDRESS by itself? 😕

EDIT: Actually I'm much more confused. Do you want DBUS_SESSION_BUS_ADDRESS to equal DBUS_SESSION_BUS_ADDRESS or the value contained in DBUS_SESSION_BUS_ADDRESS?
 
Check out his original thread, n0c. He's trying to get a session-specific DBUS_SESSION_BUS_ADDRESS into a cron job, which is difficult because cron doesn't use the same environment as the session he wants to pull the info from.

OP, I don't think that the way you're trying is going to work, regardless of syntax. The problem is that the variable doesn't exist in cron's environment. Adding export statements is pointless - if you run that script from cron, the variable still isn't available to export, because the script is started from cron's env. I would try to either a) get that variable into a text file when the session is started (then your script can parse it) or b) find a way to talk to dbus directly and get the information from there. Not knowing a lot about dbus, I'm not sure how to accomplish either of these choices, but I'm pretty sure that playing around with export statements is not going to get you anywhere.

Also, out of idle curiosity, what are you doing with rhythmbox that you want it to turn off and on every minute?
 
OK, here's a simple, dirty way. I don't know enough about dbus to say whether it's correct or reliable. Just create a script savebusaddress.sh that does...

echo $DBUS_SESSION_BUS_ADDRESS > ~/.busaddress

Make it executable and add the savebusaddress.sh script to your GNOME session (System->Pref->Sessions). Then your cron script startstoprb.sh looks like...

export DBUS_SESSION_ADDRESS="`cat ~/.busaddress`"
rhythmbox-client --play-pause

Seems like that should work.

edit: one >, not two
 
Also, just use:

DBUS_SESSION_BUS_ADDRESS="`cat ~/.busaddress`" rhythmbox-client --play-pause

if you want the environment variable to be in scope only for this one invocation of rhythmbox-client.
 
Thanks for the replies!

I have thought of doing what cleverhandle described but I was hoping that I can get away with it 😛 I didn't know that cron runs its own environment so that bit helps a lot.

I'm not trying to run it every minute, just every Monday to Friday at 9am so I can wake up to my playlist 😉 I used "--play-pause" just for testing - it stops if it's playing and vice versa.


Edit: BTW it works perfectly. Thanks!
 
Back
Top