将shell脚本设置为utf8 [英] Setting shell script to utf8

查看:4855
本文介绍了将shell脚本设置为utf8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在shell脚本中写入以下命令行:

I want to write to following command line into a shell script:

cat text.tsv |
grep -Pvi '.\t.\t.*\bHotels|Гостиница|Готель|Отель|Хотел|ホテル|מלון|فندق|होटल|โรงแรม|숙박|호텔|宾馆|旅店|旅馆|酒店|飯店\b' |
awk '{print $0,"\t","column1"} > Text2.tsv

但是,当我将其放入.sh文件时,所有非ascii字符都会被忽略:

However when I put this into a .sh file all non ascii characters get ommited:

cat text.tsv |
grep -Pvi '.\t.\t.*\bHotels|?????????|??????|?????|?????|???|????|????|????|??????|??|??|??|??|??|??|??\b' |
awk '{print $0,"\t","True"} > Text2.tsv

如何将.sh文件设置为UTF-8?我试过了:

How do I set my .sh file into UTF-8? I tried:

iconv -c -f ASCII -t UTF-8 Test.sh > Test2.sh 

但这似乎不起作用.

推荐答案

Bash负责您的语言环境设置.

Bash takes care of your locale settings.

locale

如果不在UTF-8中,您会这样:

If not in UTF-8, you do like this:

export LANG=C.UTF-8

这篇关于将shell脚本设置为utf8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆