Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In my Linux box, sleep accepts seconds, minutes and hours. So:

sleep 10m

Sleeps for 10 minutes (or 600s).

sleep on Mac only accepts seconds as argument. sleep 10m doesn't work, only sleep 600s.

What can I do? Create a function named sleep that converts when 10m or 10h is passed as a parameter to seconds, and calls the builtin sleep?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

You could use homebrew for Mac OS X: https://github.com/mxcl/homebrew and install the coreutils package from there. That will allow you to install the GNU version of sleep that handles the same parameters as the linux version.

Note that by default it installs the binaries with a 'g' prefix, so the command will actually be named gsleep, but the package provides a script file to alias all commands.

share|improve this answer
    
This solves my problem, I'm already using homebrew. Thanks! –  Somebody still uses you MS-DOS Mar 20 '11 at 16:19
add comment

sleep on Linux accepts seconds too (at least all the versions I've ever seen); can't you just use sleep 600 on both?

share|improve this answer
    
What if I want to do sleep 16m? Will I have to calculate 16*60 or X*60 everytime I have a different sleep time? This doesn't seems practical to me. –  Somebody still uses you MS-DOS Mar 20 '11 at 16:18
2  
This has the advantage that it should work on all POSIX-compliant systems. –  ninjalj Mar 20 '11 at 17:01
    
@Somebody: You could write a function sleepmin() { sleep $(($1 * 60)); }, at least under bash. –  intuited Mar 20 '11 at 17:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.