Menu

#1 Return error code of command executed by sudo

open
nobody
None
5
2008-04-06
2008-04-06
Anonymous
No

The following script works with sudo:

#!/bin/bash
# Return code example

if sudo mount /mnt/test /dev/mapper/loop0
then
kdialog --msgbox "Mounted."
else
kdialog --msgbox "Mount failed."
fi

if using kdesudo it does not work because kdesudo does not return the errorcode from the command executed, it only checks for strings returned by sudo.

#!/bin/bash
# Return code example

if kdesudo -u root mount /mnt/test /dev/mapper/loop0
then
# executed always
kdialog --msgbox "Mounted."
else
kdialog --msgbox "Mount failed."
fi

Discussion


Log in to post a comment.

MongoDB Logo MongoDB