You are not logged in.
I need a script to invoke a window and ask yes/no question, after that this script should run "reboot" or "halt" depending on the answer.
I've downloaded gxmessage and wrote this small script
#!/bin/bash
answer=$(gxmessage "Are you sure you want to shutdown? " -buttons yes,no -print) &&
if [$answer == "yes"];
then exec sys_halt
else exit
fi
But it doesn't seem to work, tip me where am I wrong?
Last edited by tasty_minerals (2011-08-29 21:05:42)
lenovo thinkpad EDGE 13'
Offline
[ is not part of if's syntax. 'if' expects commands, and [ is a command with "$answer", "=", and "yes" being arguments to it. You don't type "lsdir", you type "ls dir".
if [[ "$answer" = "yes" ]]; then
# do stuff
else
# do something else
fi
Note that usage of '==' isn't POSIX, meaning it's invalid inside [ ]. Bash will, however, accept this without whining (a bug, imo).
I suggest reading this: http://mywiki.wooledge.org/BashGuide
Last edited by falconindy (2011-08-29 19:53:56)
Offline
[ is not part of if's syntax. 'if' expects commands, and [ is a command with "$answer", "=", and "yes" being arguments to it. You don't type "lsdir", you type "ls dir".
if [[ "$answer" = "yes" ]]; then # do stuff else # do something else fi
Note that usage of '==' isn't POSIX, meaning it's invalid inside [ ]. Bash will, however, accept this without whining (a bug, imo).
I suggest reading this: http://mywiki.wooledge.org/BashGuide
thanks a lot
lenovo thinkpad EDGE 13'
Offline
well what I did is
#!/bin/bash
gxmessage "Are you sure you want to shutdown? " -buttons yes,no &&
if [[ $? == 101 ]];
then
exec sys_halt
else
exit
fi
$? contains 101(yes) or 102(no), but no effect still,
could you please be more specific. sorry
lenovo thinkpad EDGE 13'
Offline
Offline