写一个有read和if判断的shell脚本
时间: 2024-05-12 11:17:39 浏览: 111
Linux shell脚本编程if语句的使用方法(条件判断)
5星 · 资源好评率100%
Sure, here's an example shell script that includes a read statement and an if statement:
```
#!/bin/bash
echo "Enter a number:"
read num
if (( num < 10 )); then
echo "The number is less than 10"
else
echo "The number is greater than or equal to 10"
fi
```
This script prompts the user to enter a number, reads in the input using the `read` statement, and then uses an `if` statement to check whether the number is less than 10. Depending on the result of the test, the script will output either "The number is less than 10" or "The number is greater than or equal to 10".
阅读全文