awk output to export variable

558 views Asked by At

I have this command correctly build variable to export:

 dbus-daemon --session --fork --print-address | awk -F"dbus-" '{ print $2 }' | awk -F",guid=" '{print ("export DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-" $1 ",guid=" $2)}'

The output is (correctly):

export DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-YaRPQ2SYD3,guid=fa6a614c14fa3a891db3ebca5467b08f

but i'm unable to export the result to env.

How can i do the trick ? btw, i think there is a more efficient awk command to do it.

2

There are 2 answers

0
maudam On BEST ANSWER

Solved.

export DBUS_SESSION_BUS_ADDRESS=$(dbus-daemon --session --fork --print-address | awk -F"dbus-" '{ print $2 }' | awk -F",guid=" '{print ("unix:abstract=/tmp/dbus-" $1 ",guid=" $2)}')

For future reference

0
Gilles Quénot On

Try doing this :

var$(dbus-daemon --session --fork --print-address | awk -F"dbus-" '{ print $2 }' | awk -F",guid=" '{print ("export DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-" $1 ",guid=" $2)}')
echo "$var"