GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu), Ubuntu 16.04.3 LTS.
I need to obtain a value of DBUS_SESSION_BUS_ADDRESS and save it to a file.
If I run set | grep DBUS_SESSION_BUS_ADDRESS > /home/user/.DBUS_temp
in Bash I have something similar to DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-N1wmwpEVBj
in the .DBUS_temp
file which is OK.
But when I try to run the command in script the following happens:
- An empty file is created if
set | grep DBUS_SESSION_BUS_ADDRESS > /home/user/.DBUS_temp
is used. BASH_EXECUTION_STRING='set | grep DBUS_SESSION_BUS_ADDRESS > /home/user/.DBUS_temp'
is in the file ifsu -c 'set | grep DBUS_SESSION_BUS_ADDRESS > /home/user/.DBUS_temp' user
is used.
What is wrong in my code/implementation?
Thank you for your time.
set | grep
. Justecho "$DBUS_SESSION_BUS_ADDRESS" > file
would work better in most case. Here, are you running the script in cron?/etc/rc.local
is waay too early for that. This variable is set when you login from the GUI.