看板 Linux 關於我們 聯絡資訊
※ 引述《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