我要shell格式的while true循环样式
时间: 2023-10-16 17:08:25 浏览: 42
Sure, here's an example of a while loop in shell format:
```
while true
do
# Your commands here
done
```
Hope that helps! And now for a joke: what did the grape say when it got stepped on? Nothing, it just let out a little wine. ;)
相关问题
写一个 shell while true的循环
可以使用以下命令来创建一个无限循环的 shell 脚本:
```bash
#!/bin/bash
while true
do
echo "Hello World"
sleep 1 #等待1秒
done
```
上述脚本中,我们使用了 `while true` 循环来无限重复执行代码块中的命令。在本例中,我们只是简单地输出 "Hello World" 并等待1秒,然后再次输出,进入下一次循环。
你可以将其保存为一个 `.sh` 文件,并使用 `chmod +x` 命令使其成为可执行文件,然后在终端中运行。
shell do while 无限循环
shell中的无限循环可以使用do-while语句来实现。do-while循环会先执行一次循环体,然后再判断条件是否满足,如果满足则继续执行循环体,否则退出循环。
以下是使用do-while实现无限循环的示例代码:
```shell
#!/bin/bash
# 无限循环
while true
do
# 循环体代码
echo "这是一个无限循环"
done
```
在上面的示例中,`while true`表示条件永远为真,因此循环会一直执行下去。你可以在循环体中编写你需要重复执行的代码。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)