Shell Scripts for迴圈的小問題 - Linux

By Sandy
at 2015-09-02T01:02
at 2015-09-02T01:02
Table of Contents
大家好 最近在學習shell scripts (用在修改大量數據)
遇上一個問題,我想寫一個for的多重迴圈 在這裡我先簡化問題為雙迴圈好了
for ((i=1;i<=5;i=i+1));do
for ((j=1;j<=5;j=j+1));do
echo "i=${i},j=${j}"
done
done
bash這個檔案之後
會print出總共25個字串 5x5
但如果我想要自訂i的起始點,間距以及終點
所以我把scripts改寫成
read -p "i_intial= " i
read -p "i_intvl= " id
read -p "i_end= " ied
read -p "j_intial= "j
read -p "j_intvl= " jd
read -p "j_end= " jed
for ((i=${i};i<=${ied};i=${i}+${id}));do
for ((j=${j};j<=${jed};j=${j}+${jd}));do
echo "i=${i},j=${j}"
done
done
但改寫成這樣之後,他卻只會print出j的迴圈,i的迴圈卻不會work
但檢查不出問題出在哪..
請大大們幫忙了 謝謝!
--
遇上一個問題,我想寫一個for的多重迴圈 在這裡我先簡化問題為雙迴圈好了
for ((i=1;i<=5;i=i+1));do
for ((j=1;j<=5;j=j+1));do
echo "i=${i},j=${j}"
done
done
bash這個檔案之後
會print出總共25個字串 5x5
但如果我想要自訂i的起始點,間距以及終點
所以我把scripts改寫成
read -p "i_intial= " i
read -p "i_intvl= " id
read -p "i_end= " ied
read -p "j_intial= "j
read -p "j_intvl= " jd
read -p "j_end= " jed
for ((i=${i};i<=${ied};i=${i}+${id}));do
for ((j=${j};j<=${jed};j=${j}+${jd}));do
echo "i=${i},j=${j}"
done
done
但改寫成這樣之後,他卻只會print出j的迴圈,i的迴圈卻不會work
但檢查不出問題出在哪..
請大大們幫忙了 謝謝!
--
Tags:
Linux
All Comments
Related Posts
掛上的 nfs 是否能轉成 xfs?

By Bethany
at 2015-09-01T22:41
at 2015-09-01T22:41
USB Disk

By Freda
at 2015-09-01T22:40
at 2015-09-01T22:40
Apache2 + Gitlist 問題

By Ula
at 2015-09-01T18:27
at 2015-09-01T18:27
使用 GNU/Linux 做為筆電的 OS

By Margaret
at 2015-08-31T18:51
at 2015-08-31T18:51
VirtualBox 網路斷線

By Oliver
at 2015-08-30T23:17
at 2015-08-30T23:17