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