2月 21st, 2009

シェルぜ for文で区切り位置を改? にする

Posted in Linux by admin

 あるファイルからshぜ for文を利用してリスト処理をさせたい場合、以? のようなファイルの場合では改? ではなぜ 、空白を区切り位置として扱ってしまう。

$ cat test
aaa bbb ccc
111 222

$ for var in `cat list.txt`; do echo $var; done
aaa
bbb
ccc
111
222

 これを改? ? にリスト処理させたい場合は、予約変? IFSを定義してからfor文を実行すればいい。以? のようになります。

$ IFS=$'\n'; for var in `cat list.txt`; do echo $var; done
aaa bbb ccc
111 222
You can leave a comment, or trackback from your own site. RSS 2.0

2 comments

  1. Buy Ultram says:

    Hi there! I could have sworn I’ve visited your blog before but after browsing through a few of the articles I realized
    it’s new to me. Anyhow, I’m certainly pleased I found it and I’ll be book-marking it and checking back frequently!

    1月 17th, 2019 at 4:58:51

  2. Buy Tramadol Online says:

    I have to thank you for the efforts you have put in penning
    this blog. I am hoping to view the same high-grade
    content by you later on as well. In truth, your creative writing abilities has encouraged me to get my very own website now ;)

    1月 19th, 2019 at 22:04:50

Leave a comment