苹果电脑(mac)如何编写shell脚本延时操作?

2025-10-11 08:47:37

1、【延时原理】shell脚本中用sleep函数即可延时,其默认的单位为秒。如sleep 1

即为延时一秒钟。

苹果电脑(mac)如何编写shell脚本延时操作?

2、我们打开文本编辑器,输入 while true

                                                do 

                                                   echo hello 

                                                   sleep 3

                                               done

功能就是每隔3秒钟在屏幕中输出一个hello

苹果电脑(mac)如何编写shell脚本延时操作?

3、然后保存为,timewasting.sh

苹果电脑(mac)如何编写shell脚本延时操作?

4、打开终端,切换目录到保存的文件夹里,在其中输入 chmod +x timewasting.sh

这里是给文件加执行权限。

苹果电脑(mac)如何编写shell脚本延时操作?

5、然后输入  ./timewasting.sh执行。

苹果电脑(mac)如何编写shell脚本延时操作?

6、最终效果就是这样的。

苹果电脑(mac)如何编写shell脚本延时操作?

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢