Shell脚本读取文件,输出是乱码

时间:2015-12-24 07:19:20

标签: shell

环境:OS X El Capitan +终端

我的脚本如下:

    #!/bin/bash
while read line
do
    echo "LINE:"$line
done < fileName

我的源文件如下:

./Resources/Images/tmp/ic_groupon_menu@2x.png
./Resources/Images/tmp/ic_individual_logo@2x.png
./Resources/Images/tmp/ic_list_mail@2x.png
./Resources/Images/tmp/ic_log_gry@2x.png
./Resources/Images/tmp/ic_log_pen@2x.png
./Resources/Images/tmp/ic_logo_share@2x.png
./Resources/Images/tmp/ic_pig_a@2x.png
./Resources/Images/tmp/ic_price_five.png
./Resources/Images/tmp/ic_price_four.png
./Resources/Images/tmp/ic_ring_empty@2x.png
./Resources/Images/tmp/ic_ring_full@2x.png
./Resources/Images/tmp/ic_set_up@2x.png
./Resources/Images/tmp/ic_share_green@2x.png

输出如下:

LINE:??.
LINE:
LINE:
LINE:
LINE:
LINE:
LINE:
LINE:
LINE:
LINE:
LINE:
LINE:

我找不到任何有意义的词。我试图以令人费解的方式解决这个问题。

1 个答案:

答案 0 :(得分:2)

我找到了答案。源文件是UTF-16编码,UTF-16与UTF-8不同。

视图文件编码命令:

$('#clearChecked').click(function() {
  var keyWords = $('#keyWords').html();
  if ((index = keyWords.indexOf($(localArray.this).val())) !== -1) {
    localArray.splice(index, 1);
  } else {
    if ($(keyWords.this).is(':checked')) {
      localArray.push($(this).val());
    }
  }
});

用于转换文件编码的命令:

 file  pathToFile