7/1/2023 0 Comments Backslash vs forward slash![]() ![]() on second reading, this whole answer is pretty much useless trivia. The API was less than successful (I guess because it wasn't universally supported by applications), and it was removed in later versions. Useless trivia of the day - in some early versions of MS-DOS there was an API to change the command line option switch character (generally from '/' to '-') so the commands could look more Unix-like and the commands would accept '/' as a path separator on the command line. ![]() Sometimes, a slash can show a line break in a poem, song, or play. Sometimes, forward slashes function as division symbols and in place of the word or. Windows applications and APIs probably accept '\' as a separator in URIs probably because people are familiar with using backslash as a separator on those systems and URIs can also be use to represent local files. Backslash vs Forward Slash Grammar Just as mentioned in the above content, the forward slash is usually called slash and is widely used. URIs are a similar but different animal from file paths, and URIs should always use '/' to separate components. In fact, if I recall correctly, even MS-DOS accepted '/' as a path separator at the API level ever since it started supporting subdirectories (v2.0) - but by that time the '/' character had already been established as the 'switch' character for command line options, so the backslash became the defacto path separator on DOS (and later Windows). So, what is the right way? If there is any, I would say it's the / because UNIX-like operating systems were out there way before Microsoft implemented directory support into their DOS.Īs far as file system path separators go, I believe that on Windows all APIs will accept forward slashes (but perhaps there are some buggy ones that don't) - the problem is that most applications don't accept them (or parse them incorrectly). There are many artifacts of computer history in modern operating systems, which I suppose most people don't realize, but still have a major influence on how they work. MS-DOS 1.0, a quick rebrand of Q-DOS, is a CP/M derived operating system, from which it inherited drive letters (A: C: etc.)Īs in later versions they wanted to add some directory support, they chose to use the \ since the / already had another meaning in their operating system. They used the / character for parameters from programs (program /a /b) When Microsoft release MS-DOS version 1.0, it did not have directory support. When UNIX was created, or should I rather say UNICS, they chose the / as separator for directories.īack in the days, storage media was rather small, and every directory in the root was another mounted storage device (/bin /lib etc.) The difference being the use of call and doubling the %s, and the final line will show !f! as just that - a literal, since outside of delayedexpansion mode, ! is just another character with no special meaning to cmd.The reason for this is a little piece of history. The last line is simply to show that the final value acquired by f can be accessed outside of the loop as either %f% or !f!, and that %%f is out-of-context and shown as %f.Īnother way to do this without delayedexpansion is for.%%f.do ( This sets the value of f in the required manner (of course, you could always change the name to avoid confusion.) The twist, of course, is that you must use delayedexpansion and the !var! syntax to access the modified value of an environment variable within a block. Metavariables cannot be used in string-manipulation statements like substrings or substitutes, only common environment variables can be used for these operations, hence you need to assign the value of the metavariable f to the environment variable f and then perform the string-substitution task of the environment variable f. This variable can be accessed by using %f% but within a block, it will appear to retain the value it had when the controlling for was parsed (in fact, any %var% is replaced at parse-time by the value of var at that time) The second is the common environment variable f which is established by the set "f=." statement. The first is the loop-control 'metavariable' called f and referenced by %%f. Your code contains two separate variables called f. Note therefore the use of CALL ECHO %%var%% which displays the changed value of var. Two common ways to overcome this are 1) to use setlocal enabledelayedexpansion and use !var! in place of %var% to access the changed value of var or 2) to call a subroutine to perform further processing using the changed values. Hence, IF (something) else (somethingelse) will be executed using the values of %variables% at the time the IF is encountered. Any %var% within the block will be replaced by that variable's value at the time the block is parsed - before the block is executed - the same thing applies to a FOR. Within a block statement (a parenthesised series of statements), the entire block is parsed and then executed.
0 Comments
Leave a Reply. |