跳转至

6. while循环

6.1 while循环

while [ 1 -gt 2 ];do echo hello;sleep 1;done

6.1.1 脚本放入后台执行

vim while_uptime.sh
#!/bin/bash
while true
do 
    uptime && uptime >>/tmp/uptime.log
    sleep 2
done

后台执行脚本

bash while_uptime.sh &

查看后台脚本进程号

#方法1
ps -ef |grep while_uptime.sh
#方法2
jobs -l

后台程序放入前台

fg 1

疑问:前台正在执行的程序,能在不中断的情况下放入后台吗?


最后更新: 2022-02-19 13:59:07