I created a shell script /usr/local/bin/suspend
with the following content:
#! /bin/sh
# Take an optional delay parameter
if [ "$#" -gt "0" ]; then
sleep "$1"
fi
# Put the system to sleep
dbus-send --system --print-reply --dest="org.freedesktop.Hal" \
/org/freedesktop/Hal/devices/computer \
org.freedesktop.Hal.Device.SystemPowerManagement.Suspend \
int32:0
If I chmod +x
and run the script by invoking it directly (e.g., just typing suspend
or /usr/local/bin/suspend
on the command line), nothing happens and the shell hangs—it doesn't even respond to Ctrl-C; I have to switch to a new shell and kill the bash
process (which has no apparent children).
The script works fine if I invoke it in any of the following ways:
- Using
sh /usr/local/bin/suspend
. - Using
. /usr/local/bin/suspend
. - Renaming it to
suspend.sh
and invoking/usr/local/bin/suspend.sh
(or justsuspend.sh
, since it's in thePATH
).
The last option is fine, but still I wonder: what exactly is wrong with not using the .sh
extension?
which
didn't help, becausesuspend
is a builtin.