0

When I work with Bash scripts, I always create files using vi.

I am debugging a script that in theory is written correcly and I decided to check the files I have created using the file command. This is what I see.

myScript1  Bourne-Again shell script text executable, Unicode text, UTF-8 text
myScript2  ASCII text
myScript3  POSIX shell script text executable, ASCII text
myScript4  Unicode text, UTF-8 text

How can four scripts created on the same day by vi have different encodings?

The one I am debugging is ASCII text

How do a change this to Bourne-Again shell script text executable, Unicode text, UTF-8 text?

1
  • file just gueses the type of a file based on its content. So we'd need to see something of the content of these files. The shebang (#!) line at very start of a file may be different and file will read a different type of shell script. Also the difference between ASCII text and UTF-8 text may simply be if there are any multi-byte characters in it (character codes > 127). File must guess the difference between UFT-8 and ASCII because there is no actual difference between the bytes. But if no character codes > 127 are found then ASCII and UTF-8 are identical. Commented Oct 29, 2023 at 15:43

1 Answer 1

1

file just gueses the type of a file based on its content. We'd need to see something of the content of these files.

At a guess of what's happening:

The two different types of script may be caused by different shebang (#!) line at very start of a file.

The difference between ASCII text and UTF-8 text may simply be if there are any multi-byte characters in it (character codes > 127). File must guess the difference between UFT-8 and ASCII because there is no actual difference between the bytes.

But if no character codes > 127 are found then ASCII and UTF-8 are identical.

1
  • you are right. THANKS!
    – Duck
    Commented Oct 29, 2023 at 15:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .