我們可以用Loop輸出, 並在script外面把stdout 轉向到檔案上:
vi test.sh
#!/bin/bash
for i in {1..10}
do
echo "this is output"
done
chmod +x test.sh; ./test.sh >out; cat out
但我找書找來找去卻沒有方法讓script可以從一個檔案一行一行輸入並處理
假設有個檔案長這樣
#1
aa 1 2 3
bb 2 3 4
#2
dd 33 5 1
df 5 61 2
#3
fe 3 5 1
gg 64 12 12
有沒有人知道要怎麼弄一個script讓這檔案一行一行輸入處理?
#!/bin/bash
for (某i行檔案; i++) do
line=第i行檔案內容
if (line第一個字==#); then
..............
fi
done
--
vi test.sh
#!/bin/bash
for i in {1..10}
do
echo "this is output"
done
chmod +x test.sh; ./test.sh >out; cat out
但我找書找來找去卻沒有方法讓script可以從一個檔案一行一行輸入並處理
假設有個檔案長這樣
#1
aa 1 2 3
bb 2 3 4
#2
dd 33 5 1
df 5 61 2
#3
fe 3 5 1
gg 64 12 12
有沒有人知道要怎麼弄一個script讓這檔案一行一行輸入處理?
#!/bin/bash
for (某i行檔案; i++) do
line=第i行檔案內容
if (line第一個字==#); then
..............
fi
done
--
All Comments