Linux - Script dialog using xmessage

By xngo on June 23, 2019

Using xmessage to display a text dialog with a question: "Are you sure you want to reboot?" If you user clicked, on yes, it will reboot your computer by issuing the command systemctl reboot.

#!/bin/sh
 
answer=$(xmessage  "Are you sure you want to reboot?" -buttons yes,no -print)
if [ "$answer" == "yes" ];then
   systemctl reboot
fi

Output

Output of xmessage dialog

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.