4 ms·
I'm so happy to see arguments specified with "-" and "--" (UNIX-style) instead of "/" (DOS-style). The DOS-style CLI arguments used by Microsoft's other comman
by m0dest 11y ago
I'm so happy to see arguments specified with "-" and "--" (UNIX-style) instead of "/" (DOS-style).
The DOS-style CLI arguments used by Microsoft's other command line tools seem like such a stubborn throwback to a long-lost war. "/" won the battle for folder path separators (see: URLs) and "-" won the battle for argument delimiters.
- david-given 11y agoFun fact: most MS kernels, including DOS, supported "/" as a path separator. They were just filtered out of the command lines by the argument passing code. There was a system call which would tell the argument parser that you wanted a different switch character, and if you changed it to, say, "-", then "/" would work. Of course, not everything used the standard argument parser, so if you did change this you ended up in a world of pain because your tools would start behaving inconsistently, but it was theoretically possible. I've seen references to this code existing as late as XP, but I don't do Windows any more, so can't comment on later versions.
- userbinator 11y agohttps://blogs.msdn.microsoft.com/larryosterman/2005/06/24/why-is-the-dos-path-character/ https://blogs.msdn.microsoft.com/larryosterman/2005/06/24/wh... http://www.htl-steyr.ac.at/~morg/pcinfo/hardware/interrupts/inte2zxs.htm http://www.htl-steyr.ac.at/~morg/pcinfo/hardware/interrupts/...
- nolok 11y agoIn terms of file path, windows seems to always support \\ or /, both in API or in software like Explorer. That's still true for Windows 10. That leads to some interesting answers on stackoverflow sometimes about cross compatibility, where the correct answer of "use whatever constant your language has for directory separator" gets down-voted in favor of "use forward slash everywhere".
- pjmlp 11y agoBecause it isn't the correct answer. Many applications assume \ and deal with paths directly, instead of using the Windows APIs for path manipulation. This means the moment your application gives a / to another application, there is a high probability that it will break, regardless of what the Windows API supports. Even cmd doesn't handle / properly.
- nolok 11y agoI know, you will notice I said above "the correct answer [...] gets down-voted", I was not suggesting using forward slash was the way to go. You can take it as a side criticism of how things are turning sour on stackoverflow with "popular" being more valuable that "right", I guess.
- tracker1 11y agoBut a path in windows is very unlikely to start with / ... went through some serious pain trying to pass the command options to a windows program from a bash script last night in fact, so it's very fresh in my memory.
- jasode 11y ago>The DOS-style CLI arguments used by Microsoft's other command line tools seem like such a stubborn throwback to a long-lost war. "/" ... "-" ... The reasons were technical[1] instead of a stubborn resistance. The hyphen "-" was allowed in DOS/Windows filenames. The "/" was not. Therefore, if you programmed your command utility to use "-" as command line switches to match UNIX convention, your app would be "broken" because it couldn't accept filenames that began with hyphens such as "-verify.txt" If you then try to mitigate that with an "escape" switch such as double-hyphen "--" to turn off the hyphen processing, that means you can't operate on files that are named as "--". (Viruses and malware love creating files with legal filenames that utilities can't open.) So then you layer another hack on top of that and create the mother of all escape sequences with something like "--switch_character=-" (and then cross your fingers that nobody has a file that's actually named "--switch_character=-". (Arguably, you could make "myapp -- --" be unambiguous by imposing a rule that position is significant (the 1st "--" is parsed as a semantics switch, and the 2nd "--" is parsed as the oddly named file) but now you've given up the flexibility of specifying parameters in any order which many UNIX utilities do allow.) Instead of all that complication, you just let "/" be the switch character and it's easier because "/" is already an illegal character for filenames. (When in Rome...[2]) [1]https://en.wikipedia.org/wiki/8.3_filename#Directory_table https://en.wikipedia.org/wiki/8.3_filename#Directory_table [2]https://en.wiktionary.org/wiki/when_in_Rome,_do_as_the_Romans_do https://en.wiktionary.org/wiki/when_in_Rome,_do_as_the_Roman...
- bluefinity 11y agoI don't think that's the reason, you could just quote the filename (which is commonly done if the name contains spaces anyway): myapp "-verify.txt"
- jasode 11y agoRelying on quotes as special characters is not that simple to parse either: http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx http://blogs.msdn.com/b/twistylittlepassagesallalike/archive... That article also doesn't go into the difficulties of quotes in legacy DOS apps. Passing/ignoring quotes in DOS command lines was extremely difficult compared to the Win32 API. The CMD.EXE would eat the quote delimiters and your app wouldn't even see them. (It's been many years since I last tested this so a new OS like Windows 10 may have changed things.)
- deleted 11y ago[deleted]
- Kurtz79 11y ago"You make it sound like people killed and died over this." He really did not. Also, https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html
- tracker1 11y agoLOL, just last night I was updating my start-ssh-agent[1] script for bash in windows to parallel the logic of the cmd file that comes with msysgit[2]. I spent hours trying to figure out a way to pass `/IM` to taskkill without it expanding out to `/c/.../IM` from bash itself... before finally finding a solution[3], when I stopped searching for a generic answer[4]. Painful to say the least. [1] https://github.com/tracker1/msysgit/blob/patch-1/bin/start-ssh-agent.sh https://github.com/tracker1/msysgit/blob/patch-1/bin/start-s... [2] https://github.com/msysgit/msysgit/blob/master/cmd/start-ssh-agent.cmd https://github.com/msysgit/msysgit/blob/master/cmd/start-ssh... [3] http://stackoverflow.com/questions/34647591/passing-windows-slash-based-parameters-to-a-program-from-bash-script/ http://stackoverflow.com/questions/34647591/passing-windows-... [4] http://stackoverflow.com/questions/30195353/trouble-running-taskkill-from-gitbash/34179983#34179983 http://stackoverflow.com/questions/30195353/trouble-running-...