How do I fix warning: command substitution: ignored null byte in input?

I have a script that runs that needs to use notify-send, but runs as root. The only thing I found that works is this script . The problem is that on this line:

DBUS_SESSION=`grep -z DBUS_SESSION_BUS_ADDRESS /proc/$DBUS_PID/environ | sed -e s/DBUS_SESSION_BUS_ADDRESS=//`

I keep getting the error

warning: command substitution: ignored null byte in input

How do I fix or suppress the error message?
By the way the following don't suppress it:

2> /dev/null
> /dev/null
>> /dev/null
> /dev/null 2>&1
2>&1

This warning appears to be a new feature in Bash-4.4 - see for example Command substitution with null bytes generates warning.

One option would be to strip off or convert the null byte in your pipeline e.g.

DBUS_SESSION=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$DBUS_PID/environ | tr '\0' '\n' | sed -e s/DBUS_SESSION_BUS_ADDRESS=//)

(note that I switched to the modern $(. . .) form of command substitution, in place of backticks).

Alternatively, you could use the bash shell's builtin read command, which can deal with null delimiters directly e.g.

IFS== read -d '' _ DBUS_SESSION < <(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$DBUS_PID/environ)

(split the null-delimited grep output into two tokens separated by the = character; assign the first to junk variable _ and the second to DBUS_SESSION).

[I couldn't really test these as I don't have a suitably recent version of bash]