0

I am a long-time Linux user and am used to a command like:

echo 'hello' > a.txt

creating a plaintext file simply containing 'hello'.

Now, if I use the same command in Windows PowerShell, the resulting file is claimed to be binary (by git). If I inspect the file in a text editor, the file contains the text but some weird excessive characters that look like a character encoding issue.

How am I supposed to use echo instead to make it behave in a completely "ordinary" plaintext way?

Thomas Arildsen
  • 1,079
  • 2
  • 14
  • 31
  • 1
    Possible duplicate of [Using redirection within the script produces a unicode output. How to emit single-byte ASCII text?](https://stackoverflow.com/questions/1707397/using-redirection-within-the-script-produces-a-unicode-output-how-to-emit-singl) –  Apr 10 '19 at 11:27
  • Ah OK, that seems related. It could sound like the `echo` output gets UTF-16 encoded and then git may have a problem, cf. https://stackoverflow.com/questions/777949/can-i-make-git-recognize-a-utf-16-file-as-text – Thomas Arildsen Apr 10 '19 at 11:31
  • FWIW [PowerShell Core](https://github.com/powershell/powershell) aka PowerShell 6 (which is specifically designed to work well on Linux and thus play nice with things like Git as well) uses a more sensible default of UTF-8 without a BOM. – Jeroen Mostert Apr 10 '19 at 11:35
  • See also the accepted answer to this question [changing-powershells-default-output-encoding-to-utf-8](https://stackoverflow.com/questions/40098771/changing-powershells-default-output-encoding-to-utf-8) –  Apr 10 '19 at 11:39
  • 2
    @ThomasArildsen it's not the use of `echo` that causes it - it's the default behavior of `>` that causes UTF-16LE encoding – Mathias R. Jessen Apr 10 '19 at 15:35

0 Answers0