0

I have a file which has some Russian chars in it. Below is the content of my 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
tripleee
  • 175,061
  • 34
  • 275
  • 318

1 Answers1

0

It looks like you are missing the hash sign (#) at the beginning of your shebang. Creating a file with this content (test.sh):

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

and then making it executable with chmod +x test.sh produces an executable script as expected.

$ file test.sh
test.sh: POSIX shell script text executable, UTF-8 Unicode text
Marcus
  • 3,216
  • 2
  • 22
  • 22
  • Hi Marcus, Thanks for your reply. Is there any specific editor or something you use to create the test.sh file? i tried the same._#!/bin/sh sed -i "s/\bVAR1\b/Привет, как ты/g" file1.txt_ and i saved it using notepad - Encoding as UTF-8. Then tried the file command to check the format of the file and got the below bash-4.1$ file test.sh test.sh: UTF-8 Unicode (with BOM) text, with CRLF line terminators i ran the chmod +x test.sh but still it shows the – Venkatesan Sundar Jan 04 '19 at 21:05
  • I used vim on MacOS. This post details that it is likely a problem with the BOM. If there is an option to do UTF-8 without BOM that should be used. https://stackoverflow.com/questions/19065522/shebang-executable-not-found-because-of-utf-8-bom-byte-order-mark – Marcus Jan 04 '19 at 21:15
  • Thank you Marcus. It worked without BOM. BOM was the issue. You saved my day – Venkatesan Sundar Jan 04 '19 at 21:51