OSX bash“睡眠”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12803631/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 03:30:26  来源:igfitidea点击:

OSX bash "sleep"

macosbashshell

提问by Chuck

I'm trying to suspend or "sleep" a specific line in a bash script running in OSX. The script runs at startup before login. I'm not seeing the results I'm expecting. In other words no matter what time I specify after "sleep" the script still moves right along with no delay what so ever. However when I run the script after login, the "sleep" command seems to work just fine.

我正在尝试暂停或“休眠”OSX 中运行的 bash 脚本中的特定行。该脚本在登录前启动时运行。我没有看到我期待的结果。换句话说,无论我在“睡眠”后指定什么时间,脚本仍然会立即移动,没有任何延迟。但是,当我在登录后运行脚本时,“sleep”命令似乎工作得很好。

Is it possible that the command file "sleep" isn't in the path before login or before my script runs? Would it help if I placed the path to sleep before the command? If so where does "sleep" live?

在登录之前或我的脚本运行之前,命令文件“sleep”是否可能不在路径中?如果我在命令之前放置睡眠路径会有帮助吗?如果是这样,“睡眠”住在哪里?

Is there another approach or alternative command I could try?

我可以尝试另一种方法或替代命令吗?

Thanks

谢谢

#!/bin/bash

#Create the bin directory
sudo mkdir /usr/local/bin

sleep 10

#Copy the files to the Hard Drive
sudo cp /Volumes/NO\ NAME/adbind.bash /usr/local/bin/adbind.bash
sudo cp /Volumes/NO\ NAME/com.sjusd.adbind.plist /Library/LaunchDaemons/com.sjusd.adbind.plist

#Fix permissions
sudo chown root:wheel /usr/local/bin
sudo chmod 755 /usr/local/bin
sudo chown root:wheel /Library/LaunchDaemons/com.sjusd.adbind.plist
sudo chmod 755 /Library/LaunchDaemons/com.sjusd.adbind.plist

exit 0

Dang tough crowd I got a minus 1 LOL

该死的强硬人群我得到了负 1 LOL

回答by Webbie

This might be a little late, but it seems that sleep on OS X doesn't work with quantifiers (m,h, ...). Official Apple documentation

这可能有点晚了,但似乎 OS X 上的 sleep 不适用于量词 (m,h, ...)。苹果官方文档

So "sleep 5m" is the same as "sleep 5". If you want 5 minutes, you have to use "sleep 300"

所以“sleep 5m”和“sleep 5”是一样的。如果你想要5分钟,你必须使用“sleep 300”

回答by Barton Chittenden

If you run which sleep, you can get the path to 'sleep' on your system. I get /bin/sleep.

如果您运行which sleep,您可以获得系统上“睡眠”的路径。我明白了/bin/sleep

At this point, you have a couple of options:

此时,您有几个选择:

you can specify the path to sleepwhen you call it

您可以指定sleep调用它时的路径

#!/bin/bash
# script before sleep ...
/bin/sleep
# ... after sleep

or you can add the path to your $PATHvariable within your script before you call it.

或者您可以$PATH在调用之前在脚本中添加变量的路径。

#!/bin/bash
PATH="$PATH:/bin"
# script before sleep ...
sleep
# ... after sleep