1

To find every line with that "-" from the command wsl --help, theses lines work

 wsl --help | Select-String -Pattern "-"
 wsl --help | Select-String "-"

Now I try with more complicated pattern: "--"

  wsl --help | Select-String -Pattern "--"
  wsl --help | Select-String "--"

Nothing is return although there is line with this pattern. Why?

updated:

  wsl --help | Select-String "--" -SimpleMatch

doesn't work either

1 Answers1

1

Yep, wsl outputs utf16le or unicode. Even bytes are null.

 wsl --help | select -first 1 | format-hex


   Label: String (System.String) <09F5DDB6>

          Offset Bytes                                           Ascii
                 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
          ------ ----------------------------------------------- -----
0000000000000000 43 00 6F 00 70 00 79 00 72 00 69 00 67 00 68 00 C o p y r i g h
0000000000000010 74 00 20 00 28 00 63 00 29 00 20 00 4D 00 69 00 t   ( c )   M i
0000000000000020 63 00 72 00 6F 00 73 00 6F 00 66 00 74 00 20 00 c r o s o f t
0000000000000030 43 00 6F 00 72 00 70 00 6F 00 72 00 61 00 74 00 C o r p o r a t
0000000000000040 69 00 6F 00 6E 00 2E 00 20 00 41 00 6C 00 6C 00 i o n .   A l l
0000000000000050 20 00 72 00 69 00 67 00 68 00 74 00 73 00 20 00   r i g h t s
0000000000000060 72 00 65 00 73 00 65 00 72 00 76 00 65 00 64 00 r e s e r v e d
0000000000000070 2E 00                                           .

"`0" means null. In powershell 7, the matches are highlighted.

wsl --help | Select-String -Pattern "-`0-" | select -first 1

    --exec, -e <CommandLine>

js2010
  • 23,033
  • 6
  • 64
  • 66