Ubuntu – Display terminal command result in Desktop notification

command linegnome-terminalnotificationnotify-send

I need to display the result of a terminal command in notification.

Notifications can be triggered by running:

notify-send "Notification message"

The command I have is:

sudo /opt/lampp/xampp start

which shows the following result in terminal:

Starting XAMPP for Linux 5.6.20-0...
XAMPP: Starting Apache...already running.
XAMPP: Starting MySQL...already running.
XAMPP: Starting ProFTPD...already running.

I want this result to be displayed in notification just like "Notification message" is displayed with notify-send.

Thanks!

Best Answer

In most cases you can use notify-send with command substitution $(). For example:

notify-send "XAMP Start" "$(sudo /opt/lampp/xampp start)"

Inside a scrip you can use a function to wrap the entire output:

#!/bin/bash
main() { echo "Line 1"; echo "Line 2";  echo "Line 3"; }
notify-send "Script output" "$(main)"

If you need to run that function with sudo:

notify-send "Script output" "$(sudo bash -c "$(declare -f main); main")"