Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
746 views
in Technique[技术] by (71.8m points)

unix - How do I change a shell scripts character encoding?

I am using Gina Trapiani's excellent todo.sh to organize my todo-list.

However being a dane, it would be nice if the script accepted special danish characters like ø and æ.

I am an absolute UNIX-n00b, so it would be a great help if anybody could tell me how to fix this! :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Slowly, the Unix world is moving from ASCII and other regional encodings to UTF-8. You need to be running a UTF terminal, such as a modern xterm or putty.

In your ~/.bash_profile set you language to be one of the UTF-8 variants.

export LANG=C.UTF-8
or
export LANG=en_AU.UTF-8
etc..

You should then be able to write UTF-8 characters in the terminal, and include them in bash scripts.

#!/bin/bash
echo "UTF-8 is gr?at ?"

See also: https://serverfault.com/questions/11015/utf-8-and-shell-scripts


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...