Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 11735  / 2 Years ago, sat, june 18, 2022, 6:32:49

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


More From » bash

 Answers
3

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.


[#26899] Sunday, June 19, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rontablis

Total Points: 293
Total Questions: 123
Total Answers: 104

Location: Austria
Member since Mon, Mar 1, 2021
3 Years ago
;