網站首頁 編程語言 正文
Linux命令行,循環執行shell命令
死循環
命令格式
while true ;do <command>; done;
可以將 command 替換為任意命令。
下面以echo “hello”; sleep 1;為 command 展示最終效果
效果
wanghan@ubuntu:~$ while true ;do echo "hello"; sleep 1; done;
hello
hello
hello
hello
hello
^C
wanghan@ubuntu:~$
每隔一秒,打印一次hello,直到按下Ctrl+C才停止。
普通計數循環
循環10次
mycount=0; while (( $mycount < 10 )); do <command>;((mycount=$mycount+1)); done;
可以將 command 替換為任意命令。
下面以 echo “mycount=$mycount”;為 command 展示最終效果
效果
wanghan@ubuntu:~$ mycount=0; while (( $mycount < 10 )); do echo "mycount=$mycount"; ((mycount=$mycount+1)); done;
mycount=0
mycount=1
mycount=2
mycount=3
mycount=4
mycount=5
mycount=6
mycount=7
mycount=8
mycount=9
mycount計數到10后停止循環。
以上內容到此介紹,下面介紹下Linux shell循環命令。
Linux shell循環命令 while死循環的用法
作為硬件工程師,偶爾會用到Linux shell編程,這里只將while死循環,有相關需求的工程師可以參考。
死循環也就是無限循環,它由 while true (表示條件始終為真)或 while : (表示空表達式)組成,其中冒號(:)等效于無操作,冒號和while之間有空格。實例代碼如下:
#!/bin/bash
while true #same to while :
do
echo "drink more water!!"
done
運行結果如下:
root@nihao:~# ./nihaoaaaa.sh
drink more water!!
drink more water!!
drink more water!!
drink more water!!
drink more water!!
drink more water!!
drink more water!!
drink more water!!
...
原文鏈接:https://blog.csdn.net/daoshuti/article/details/72831256
相關推薦
- 2023-02-01 特定用例下的Combine全面使用詳解_Swift
- 2022-05-21 Python遞歸時間復雜度_python
- 2022-01-26 關于(NOTICE)iconv(): Detected an illegal character i
- 2022-11-27 C語言中花式退出程序的方式總結_C 語言
- 2022-09-19 .Net?Core使用layui多文件上傳_實用技巧
- 2022-06-24 使用Go語言寫一個Http?Server的實現_Golang
- 2022-08-25 pycharm中keras導入報錯無法自動補全cannot?find?reference分析_pyt
- 2022-10-04 C語言指針和數組深入探究使用方法_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支