Re: [問題] for loop 的單位

看板Linux作者 (lloyd huang)時間16年前 (2009/06/16 00:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/3 (看更多)
※ 引述《Xphenomenon (啦 )》之銘言: : 我有一個檔案內容如下,以 tab 鍵切開: : test.txt : a 1 : b 2 : c 3 : d 4 : for i in `cat test.txt`; do echo $i; done : 輸出: : a : 1 : b : 2 : c : 3 : d : 4 : 請教: : 我如何能夠讓 i 包含一整行,因為我需要近一步的把欄位切開, : 我需要同時處理如 a 和 1 的值。麻煩了,感謝! :> =============> You need to know IFS special variable. please try below. IFS='' for i in `cat test.txt` ; do echo $i ; done unset IFS for i in `cat test.txt` ; do echo $i ; done $> man bash IFS The Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read builtin command. The default value is ``<space><tab><newline>''. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.127.60.21
文章代碼(AID): #1ADd1DfJ (Linux)
文章代碼(AID): #1ADd1DfJ (Linux)