编写Shell脚本程序,执行后打印一行提示“Please input a number:”,逐次 打印用户输入的数值,直到用户输入“end”为止。 编写Shell脚本,使用ping命令检测192.168.3.1~192.168.3.100共100个主机。 是否可以ping通? 编写Shell脚本,提示输入某个目录文件名,然后输出此目录中所有文件的权限, 若可读输出readable,若可写输出writeable,若可执行输出executable。
时间: 2024-03-12 08:50:18 浏览: 37
好的,下面是您提出的三个问题对应的Shell脚本程序。
1. 逐次打印用户输入的数值,直到用户输入“end”为止。
```bash
#!/bin/bash
echo "Please input a number:"
read input
while [ "$input" != "end" ]
do
echo "You input: $input"
echo "Please input a number:"
read input
done
echo "End of program."
```
2. 使用ping命令检测192.168.3.1~192.168.3.100共100个主机是否可以ping通。
```bash
#!/bin/bash
for i in {1..100}
do
ip="192.168.3.$i"
ping -c 1 $ip > /dev/null
if [ $? -eq 0 ]
then
echo "$ip is up."
else
echo "$ip is down."
fi
done
```
3. 输出某个目录中所有文件的权限,若可读输出readable,若可写输出writeable,若可执行输出executable。
```bash
#!/bin/bash
echo "Please input a directory:"
read dir
if [ ! -d "$dir" ]
then
echo "$dir is not a directory."
exit 1
fi
cd $dir
for file in *
do
if [ -r "$file" ]
then
echo "$file is readable."
fi
if [ -w "$file" ]
then
echo "$file is writeable."
fi
if [ -x "$file" ]
then
echo "$file is executable."
fi
done
```
希望以上程序能够满足您的需求,如果有什么问题,欢迎随时提出。
相关推荐
![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_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)
![](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)