Scripting in ANSI or UTF

A quick question. Since I’m now learning to script in bash, what is the default character set used by openSUSE? ANSI, UTF, Latin1 (which from what I read is vim’s default). My scripting is strictly for Linux and I use KWrite when on the Linux machine. Sometimes, though, I will work on it using notepad ++ on the windows machine, which at a minimum changes the EOL. Simple fix at either end, but I’d like to setup notepad ++ correctly.

Using $LANG I get:

>echo $LANG
>en_us.UTF-8

Would I be correct in presuming this is the character set I should be using?

I never contemplated about this. As long as the bash scripting sec is involved it does not matter much as only the ASCII character set is used and that is a subset of UTF-8 encoded Unicode. And as long as you use only the first 128 characters of Unicode there is no difference with ASCII.

The only place where you thus may find non-ASCII characters is in string as in

echo 'नमस्ते'

And of course you can use file names with them.

Never use odd codings like Latin-1. Only use UTF-8 encoded Unicode or the ASCII subset.

On 2014-06-15 19:06, sparkz alot wrote:
>
> A quick question. Since I’m now learning to script in bash, what is the
> default character set used by openSUSE?

UTF-8, since several years (perhaps a decade).


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)

On 2014-06-15, sparkz alot <sparkz_alot@no-mx.forums.opensuse.org> wrote:
>
> A quick question. Since I’m now learning to script in bash, what is the
> default character set used by openSUSE? ANSI, UTF, Latin1 (which from
> what I read is vim’s default).

Absolutely correct. If you do use Vim, bear in mind you can change the default encoding to UTF-8 (and others) by editing
your ~/.vimrc (I think you just need to add the line :set encoding=utf-8).

> My scripting is strictly for Linux and I
> use KWrite when on the Linux machine. Sometimes, though, I will work on
> it using notepad ++ on the windows machine, which at a minimum changes
> the EOL. Simple fix at either end, but I’d like to setup notepad ++
> correctly.

As stated by previous posters, the answer is UTF8. You may however wish to consider finding an alternative for
NotePad++. IIRC Kwrite/Kate/both can be installed on Windows (via KDE on Windows).

Thanks all. Got both ends set up for unix lf and utf-8 (without BOM). I was not aware KWrite was available for windows, but notepad++ does the job and it supports a whole array of languages, though for the foreseeable future bash is the only thing on the menu. Still so much more to learn :slight_smile:

On 2014-06-16 10:50, flymail wrote:

> Absolutely correct. If you do use Vim, bear in mind you can change the default encoding to UTF-8 (and others) by editing
> your ~/.vimrc (I think you just need to add the line :set encoding=utf-8).

Isn’t there a special comment you can put on the text files you edit, to
inform vi about the encoding used?


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)

I’m not sure about adding a “comment” to the document. The documents encoding information is embedded into the header when you save the file. you could however use a hex editor to insert what ever you want. Say I take a plain text.txt file and insert 47 49 46 38 39 61 (hex code for gif89a) then save it w/o the ‘.txt’, using dolphin or whatever file manger, will see it as a .gif file and ask if you want to open it with say gimp. Doesn’t really change the content, you won’t be able to open it with gimp, as the content is still text, but what fun :slight_smile: Then there is the dark side…

A text file (like a bash script) has no header telling what encoding is used. But an application can browse through the contents to see if there is something interpretable as UTF-8 (which btw will not be found when only the first 127 bytes of Unicode, and thus ASCII only, is used) and then take an heuristic decision.

On 2014-06-20, Carlos E. R. <robin_listas@no-mx.forums.opensuse.org> wrote:
> Isn’t there a special comment you can put on the text files you edit, to
> inform vi about the encoding used?

No. To my knowledge vi has no such facility.

On the other hand, Vim does iterate through different file encodings if errors are detected using the default encoding.
For more information, open Vim and invoke:


:help fencs

On 2014-06-23 10:39, flymail wrote:
> On 2014-06-20, Carlos E. R. <robin_listas@no-mx.forums.opensuse.org> wrote:
>> Isn’t there a special comment you can put on the text files you edit, to
>> inform vi about the encoding used?
>
> No. To my knowledge vi has no such facility.

Then it is emacs.

I know I have bumped now and then into text files, source code perhaps,
that contain a commented line near the top (ie, recognized as comment in
the syntax of that file), with some adjustments for the editor (tab
size, line size, encoding, dunno).

I have the vague recollection that they were intended for vi, or vim,
but I could be mistaken and be for emacs.


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)

On 2014-06-24, Carlos E. R. <robin_listas@no-mx.forums.opensuse.org> wrote:
> On 2014-06-23 10:39, flymail wrote:
>> On 2014-06-20, Carlos E. R. <robin_listas@no-mx.forums.opensuse.org> wrote:
>>> Isn’t there a special comment you can put on the text files you edit, to
>>> inform vi about the encoding used?
>>
>> No. To my knowledge vi has no such facility.
>
> Then it is emacs.

That is correct. Emacs does support file encoding declaration, but it must be inserted manually as the first line e.g.


# -*- coding: utf-8 -*-

Personally I think this is a terrible idea. I think some Emacs plugins (e.g. Ruby-mode) sometimes insert the line upon
saving even if you delete it!

On 2014-06-24 10:44, flymail wrote:
> On 2014-06-24, Carlos E. R. <> wrote:

>>> No. To my knowledge vi has no such facility.
>>
>> Then it is emacs.
>
> That is correct. Emacs does support file encoding declaration, but it must be inserted manually as the first line e.g.

Ah! :slight_smile:

>
>


> # -*- coding: utf-8 -*-
> 

>
> Personally I think this is a terrible idea. I think some Emacs plugins (e.g. Ruby-mode) sometimes insert the line upon
> saving even if you delete it!

Ugh.

I use neither, but I remember, on another life, that having tab
definition sizes in the text file was a help. Different tab size, when
using source indentation with tabs, is a terrible thing to see.

(on that life, the file size saved by using tabs instead of chars was
important :wink: )


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)

On 2014-06-24, Carlos E. R. <robin_listas@no-mx.forums.opensuse.org> wrote:
> I use neither, but I remember, on another life, that having tab
> definition sizes in the text file was a help. Different tab size, when
> using source indentation with tabs, is a terrible thing to see.
>
> (on that life, the file size saved by using tabs instead of chars was
> important :wink: )

… in which case, you’d love Vim! :smiley:

On 2014-06-24 19:11, flymail wrote:
> On 2014-06-24, Carlos E. R. <> wrote:
>> I use neither, but I remember, on another life, that having tab
>> definition sizes in the text file was a help. Different tab size, when
>> using source indentation with tabs, is a terrible thing to see.
>>
>> (on that life, the file size saved by using tabs instead of chars was
>> important :wink: )
>
> … in which case, you’d love Vim! :smiley:

Nay, there was no vim there. There was WordStar.

Actually, what I used was a high level language compiler, made in less
than 30 KB of assembler code, which included a complete text editor in
those 30 KB, using the WordStar user interface.

We could work with a single (360KB?) floppy, including the operating
system, the compiler/editor, and our source code and executable.


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)

On 2014-06-24, Carlos E. R. <robin_listas@no-mx.forums.opensuse.org> wrote:
> Nay, there was no vim there. There was WordStar.
>
> Actually, what I used was a high level language compiler, made in less
> than 30 KB of assembler code, which included a complete text editor in
> those 30 KB, using the WordStar user interface.
>
> We could work with a single (360KB?) floppy, including the operating
> system, the compiler/editor, and our source code and executable.

My memory of WordStar is that it came on two floppies - I think an extra one was needed for the printer drivers in the
days before unified drivers. Perhaps I had a deluxe version!

On 2014-06-25 10:17, flymail wrote:
> On 2014-06-24, Carlos E. R. <robin_listas@no-mx.forums.opensuse.org> wrote:
>> Nay, there was no vim there. There was WordStar.
>>
>> Actually, what I used was a high level language compiler, made in less
>> than 30 KB of assembler code, which included a complete text editor in
>> those 30 KB, using the WordStar user interface.
>>
>> We could work with a single (360KB?) floppy, including the operating
>> system, the compiler/editor, and our source code and executable.
>
> My memory of WordStar is that it came on two floppies - I think an extra one was needed for the printer drivers in the
> days before unified drivers. Perhaps I had a deluxe version!

That was the full fledged edition. What our teachers gave us was smaller
and fitted a single floppy.

But I was actually referring above to turbo pascal 2. :slight_smile:

The first “IDE”, with compiler, editor, with automatic jump to error
point, in less than 30 KB. Primitive compared with later IDEs, but still
astonishing, compared with what others provided.

The editor used an interface set like wordstar, the same keybindings.
Thus I soon learned most of them, and to this day, I still use them (in
jstar, aka joe). They are very efficient, designed for touch typists.


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)