Linux命令行循環(huán)執(zhí)行shell命令
Linux命令行,循環(huán)執(zhí)行shell命令
死循環(huán)
命令格式
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才停止。
普通計(jì)數(shù)循環(huán)
循環(huán)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計(jì)數(shù)到10后停止循環(huán)。
以上內(nèi)容到此介紹,下面介紹下Linux shell循環(huán)命令。
Linux shell循環(huán)命令 while死循環(huán)的用法
作為硬件工程師,偶爾會(huì)用到Linux shell編程,這里只將while死循環(huán),有相關(guān)需求的工程師可以參考。
死循環(huán)也就是無限循環(huán),它由 while true (表示條件始終為真)或 while : (表示空表達(dá)式)組成,其中冒號(hào)(:)等效于無操作,冒號(hào)和while之間有空格。實(shí)例代碼如下:
#!/bin/bash while true #same to while : do echo "drink more water?。? done
運(yùn)行結(jié)果如下:
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!!
...
到此這篇關(guān)于Linux命令行,循環(huán)執(zhí)行shell命令的文章就介紹到這了,更多相關(guān)linux shell循環(huán)執(zhí)行命令內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Linux命令創(chuàng)建日期文件夾或者文件的實(shí)例代碼
本文通過實(shí)例代碼給大家介紹了Linux命令創(chuàng)建日期文件夾或者文件的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-10-10
Linux設(shè)置每晚定時(shí)備份Oracle數(shù)據(jù)表的操作命令
這篇文章主要介紹了Linux設(shè)置每晚定時(shí)備份Oracle數(shù)據(jù)表,本文通過腳本命令給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-12-12
Linux 中shell腳本設(shè)置開頭固定格式的實(shí)現(xiàn)方法
這篇文章主要介紹了Linux 中shell腳本設(shè)置開頭固定格式的實(shí)現(xiàn)方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10
shell腳本實(shí)現(xiàn)多彩進(jìn)度條
這篇文章主要介紹了shell腳本實(shí)現(xiàn)多彩進(jìn)度條的相關(guān)資料,需要的朋友可以參考下2017-07-07

