makefile for loop 問題 - Linux
By Ina
at 2021-08-06T12:23
at 2021-08-06T12:23
Table of Contents
※ 引述《Wudc (二寶來啦!!)》之銘言:
: 想請教一下,如果有這樣一個text file,
: Text.txt:
: a1 b1 c1
: a2 b2 c2
: ...
: a100 b100 c100
: 要怎麼樣在makefile的 for loop 當中用三個變數分別代表 a1~a100 b1~b100 c1~c100呢?
: 用 for i in $$(cat Text.txt)這樣的寫法可以取出裡面的字串
: 但這樣沒辦法在一次迴圈中同時取得 a1 b1 c1
: 不得有沒有辦法在一次迴圈中同時取得a1 b1 c1的字串呢?
makefile 我不懂, 不過從 shell script 角度來看.
rickie@MBP16 0 % cat Text.txt
a1 b1 c1
a2 b2 c2
a100 b100 c100
rickie@MBP16 0 % cat Text.sh
#!/bin/bash
OldIFS=${IFS}
IFS=$'\n'
for i in $(cat Text.txt)
do
IFS=${OldIFS}
arr=($i)
printf "att1:%5s att2:%5s att3:%5s\n" ${arr[0]} ${arr[1]} ${arr[2]}
done
OBrickie@MBP16 0 % ./Text.sh
att1: a1 att2: b1 att3: c1
att1: a2 att2: b2 att3: c2
att1: a100 att2: b100 att3: c100
rickie@MBP16 0 %
或許你可以根據需要修改
--
: 想請教一下,如果有這樣一個text file,
: Text.txt:
: a1 b1 c1
: a2 b2 c2
: ...
: a100 b100 c100
: 要怎麼樣在makefile的 for loop 當中用三個變數分別代表 a1~a100 b1~b100 c1~c100呢?
: 用 for i in $$(cat Text.txt)這樣的寫法可以取出裡面的字串
: 但這樣沒辦法在一次迴圈中同時取得 a1 b1 c1
: 不得有沒有辦法在一次迴圈中同時取得a1 b1 c1的字串呢?
makefile 我不懂, 不過從 shell script 角度來看.
rickie@MBP16 0 % cat Text.txt
a1 b1 c1
a2 b2 c2
a100 b100 c100
rickie@MBP16 0 % cat Text.sh
#!/bin/bash
OldIFS=${IFS}
IFS=$'\n'
for i in $(cat Text.txt)
do
IFS=${OldIFS}
arr=($i)
printf "att1:%5s att2:%5s att3:%5s\n" ${arr[0]} ${arr[1]} ${arr[2]}
done
OBrickie@MBP16 0 % ./Text.sh
att1: a1 att2: b1 att3: c1
att1: a2 att2: b2 att3: c2
att1: a100 att2: b100 att3: c100
rickie@MBP16 0 %
或許你可以根據需要修改
--
Tags:
Linux
All Comments
By Ula
at 2021-08-10T23:35
at 2021-08-10T23:35
By Skylar Davis
at 2021-08-15T10:46
at 2021-08-15T10:46
By Rosalind
at 2021-08-19T21:57
at 2021-08-19T21:57
Related Posts
shellscript tar問題
By Annie
at 2021-08-05T21:35
at 2021-08-05T21:35
直立外接螢幕待機後無法重開
By Joseph
at 2021-08-05T14:27
at 2021-08-05T14:27
makefile for loop 問題
By Megan
at 2021-08-04T16:25
at 2021-08-04T16:25
想實現在外面連回家中的Linux主機
By Zanna
at 2021-08-03T01:42
at 2021-08-03T01:42
shellscript tar問題
By Isla
at 2021-07-31T10:55
at 2021-07-31T10:55