Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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! :)

like image 486
timkl Avatar asked Jan 10 '10 21:01

timkl


People also ask

How do I change characters on shell?

Find and replace text within a file using sed command Use Stream EDitor (sed) as follows: sed -i 's/old-text/new-text/g' input.txt. The s is the substitute command of sed for find and replace. It tells sed to find all occurrences of 'old-text' and replace with 'new-text' in a file named input.txt.


1 Answers

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

like image 52
brianegge Avatar answered Oct 11 '22 09:10

brianegge