Ubuntu – Use of default alias “alert”

bashnotification

The default alias Alert is for the command

notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"

Executing alert gives an notification with text Alert and an terminal icon.
Executing it with one param like alert !!!!! gives notification with text Alert !!!!! and !!!!!.

So, what's the difference between simple notify-send command and this complexed alias which uses notify-send, echo, history, tail and sed?

In which situations is this alias useful or was it just created for pun(Something like using sudo sudo sudo sudo sudo apt-get install

I'm using Ubuntu 12.10

Best Answer

You could use the man pages to get details about what the commands combined here do. Here's a little about the purpose of those commands here:

"$([ $? = 0 ] && echo terminal || echo error)"

This would echo terminal or error as per to the execution status - successful or fail respectively of the last command; and the result is as the value to the -i switch of notify-send for displaying the icons.

history|tail -n1

..to get the last command executed.

and sed to parse the text to display it with notify-send message.


To understand these try the following:

true; echo "$([ $? = 0 ] && echo terminal || echo error)"

..this would echo terminal.

false; echo "$([ $? = 0 ] && echo terminal || echo error)"

..this would echo error.

notify-send -i terminal 'Please note the icon..' 'the default icon for the terminal has been used. You can specify any other icon of your choice'

And,

echo $?

..is very useful to know the exit value of the last command executed.

echo "$(echo "the output of this command enclosed within \$(...)") is being supplied here in the outer echo command where is used as an argument."

..nested echo as a simple demo for using $() in a command combo.