1

I have a Windows install and would like to change the definition of a built in Windows command (notably sort) to an installed git command, so that whenever I write sort on the command line, it runs the unix version of sort instead of the Windows one. I have heard about doskey from this question, but it doesn't really work for me, since it ignores when I try to pipe other commands to it. Running where sort gives me this output:

C:\>where sort
C:\Windows\System32\sort.exe
C:\Program Files\Git\usr\bin\sort.exe

Is there any way I can have sort just run the bottom path every time instead? Thanks!

1 Answers1

1

This tells me that the alternative sort.exe is in your %path%; otherwise, it wouldn't be located with this specific where command (without tags or switches):

C:\>where sort
C:\Windows\System32\sort.exe
C:\Program Files\Git\usr\bin\sort.exe

In %PATHEXT%, observe the default output:

.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

If the .COM extension is in the first position, it means that the search for sort will specifically follow the order of locating sort.com before looking for sort.exe. This implies an explanation for why sort.bat, sort.cmd, sort.vbs, and other extension options/extensions do not work.


This makes me think that you did not choose to overwrite find and sort with the "alternative" versions proposed by the Git installer.

enter image description here


Therefore, it would be a valid attempt to simply rename the sort.exe extension to sort.com and see how it behaves with your commands and redirections (|Sort), where it would be prioritized in the order of the first occurrence in the %PATHEXT% search..


Note 1.: Since I anticipate that updates and checks for executable files may happen sporadically, simply renaming could lead to some unexpected issues (or perhaps not, who knows?) with Git actions (such as updates, file checks, etc.). Therefore, I still believe that copying sort.exe to sort.com might be a viable option that works well with / and avoids any anomalies with Git.


Note 2.: It must be considered that for scripts in execution, scheduled tasks, backups, and other ongoing activities in the system that utilize sort.exe, some edits will be necessary to accommodate the programmed actions in the expected outputs for the flags used in these scripts. If applicable, consider locating and modifying the scripts to implement the appropriate /flags that are "/compatible" with both versions or just specify the complete paths to sort.exe (%WinDir%\System32\Sort.exe) in your scripts.


Note 3: One alternative would be to place a copy of sort.exe renamed to sort.com in the C:\Windows\System32\ directory. However, I'm not sure if would "object" to the presence of this file and delete it. I have no idea what to expect when this action is taken, but it might be helpful if allows such an attempt without any "adverse" reactions.

Io-oI
  • 9,237