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
?
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 andfile
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.