Execute sh file with Russian or Chines Chars - Saved as UTF-8 or Unicode

2

I have a file which has some russian chars in. Below is the content of by sh file.

#!/bin/sh
sed -i "s/\bVAR1\b/Привет, как ты/g" file1.txt

When i save this file i had to save this as UTF-8 or Unicode format as i have some Unicode format characters in the file and i will loose those if i save as ANSI. Once i save the file , when i use the file command i get the below

bash-4.1$ file test.sh
test.sh: UTF-8 Unicode (with BOM) English text, with very long lines, with CRLF line terminators

Question : how can I make this as executable shell script file? I get the below if my file has only English chars

bash-4.1$ file test2.sh
test2.sh: POSIX shell script text executable

Thanks in advance

Venkatesan Sundar

Posted 2019-01-04T20:42:09.460

Reputation: 21

I copied your script, with similar results, but when I corrected the first line, as @KamilMaciorowski indicates, then everything works fine. Indeed, it works without the correction (giving an error on the first line), despite the file output. – AFH – 2019-01-05T16:47:16.340

Thanks for your comments. I got the script work. Had to avoid BOM chars and set fileformat=unix if the file was edited using any windows editor tools – Venkatesan Sundar – 2019-01-05T23:17:09.847

No answers