shell while循环


#!/bin/bash
# while 循环
i=0;
while [ $i -lt 10 ];do
    ((i++));
done
echo $i;

# read -p "Please input number:"
Please input number:10
root@Ubuntu:/home/shell# read -p "Please input number:" input
Please input number:100
root@Ubuntu:/home/shell# echo $input
100

while 读取文件信息,这件事for就不好处理了。

#!/bin/bash
# while read line 读取文件信息
read -p "请输入文件地址:" input
if [ ! -f $input ];then
    echo "文件不存在"
    exit
fi

# 读取文件内容
while read line
do
    echo $line
done < $input


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM