Backslash


The backslash is a typographical mark used mainly in computing and is the mirror image of the common slash. It is sometimes called a hack, whack, escape, reverse slash, slosh, downwhack, backslant, backwhack, bash, reverse slant, and reversed virgule. In Unicode and ASCII it is encoded at.

History

introduced the character into ASCII on September 18, 1961, as the result of character frequency studies. In particular, the was introduced so that the ALGOL boolean operators and could be composed in ASCII as and respectively. Both these operators were included in early versions of the C programming language supplied with Unix V6, Unix V7 and more recently BSD 2.11.

Usage

Programming languages

In many programming languages such as C, Perl, PHP, Python, Unix scripting languages, and many file formats such as JSON, the backslash is used as an escape character, to indicate that the character following it should be treated specially, or normally. For instance, inside a C string literal the sequence produces a newline byte instead of an 'n', and the sequence produces an actual double quote rather than the special meaning of the double quote ending the string. An actual backslash is produced by a double backslash.
Regular expression languages used it the same way, changing subsequent literal characters into metacharacters and vice versa. For instance searches for either '|' or 'b', the first bar is escaped and searched for, the second is not escaped and acts as an "or".
Outside quoted strings, the only common use of backslash is to ignore a newline immediately after it. In this context it may be called a "continuation" as the current line continues into the next one.
To support computers that lacked the backslash character, the C trigraph was added, which is equivalent to a backslash. Since this can escape the next character, which may itself be a, the primary modern use may be for code obfuscation. Support for trigraphs was removed in C++17.
In Visual BASIC the backslash is used as an operator symbol to indicate integer division. This rounds toward zero.
The ALGOL 68 programming language uses the "\" as its Decimal Exponent Symbol. ALGOL 68 has the choice of 4 Decimal Exponent Symbols: e, E, \, or 10. Examples:,, or.
In APL is called Expand when used to insert fill elements into arrays, and Scan when used to produce prefix reduction.
In PHP version 5.3 and higher, the backslash is used to indicate a namespace.
In Haskell, the backslash is used both to introduce special characters and to introduce lambda functions.

Filenames

2.0, released 1983, copied the hierarchical file system from Unix and thus used the slash but added the backslash to allow paths to be typed at the command line interpreter's prompt while retaining compatibility with MS-DOS 1.0 where the slash was the command-line option indicator. Except for COMMAND.COM, all other parts of the operating system accept both characters in a path, but the Microsoft convention remains to use a backslash, and APIs that return paths use backslashes. In some versions, the option character can be changed from to via SWITCHAR, which allows COMMAND.COM to preserve in the command name.
The Microsoft Windows family of operating systems inherited the MS-DOS behavior and so still support either character – but individual Windows programs and sub-systems may, wrongly, only accept the backslash as a path delimiter, or may misinterpret a forward slash if it is used as such. Some programs will only accept forward slashes if the path is placed in double-quotes. The failure of Microsoft's security features to recognize unexpected-direction slashes in local and Internet paths, while other parts of the operating system still act upon them, has led to some serious lapses in security. Resources that should not be available have been accessed with paths using particular mixes, such as.

Text markup

The backslash is used in the TeX typesetting system and in RTF files to begin markup tags.
In USFM, the backslash is used to mark format features for editing Bible translations.

Mathematics

A backslash-like symbol is used for the set difference.
The backslash is also sometimes used to denote the right coset space.
Especially when describing computer algorithms, it is common to define backslash so that is equivalent to. This is integer division that rounds down, not towards zero. In Wolfram Mathematica the backslash is used this way for integer divide.
In MATLAB and GNU Octave the backslash is used for left matrix divide, while the slash is for right matrix divide.

Confusion with ¥ and other characters

In the Japanese encodings ISO 646, JIS X 0201, and Shift JIS, the code point 0x5C that would be used for backslash in ASCII is instead rendered as a yen sign. Due to extensive use of the backslash code point to represent the yen sign, even today some fonts such as MS Mincho render the backslash character as a ¥, so the characters at Unicode code points 00A5 and 005C both render as when these fonts are selected. Computer programs still treat 005C as a backslash in these environments but display it as a yen sign, causing confusion, especially in MS-DOS filenames.
Several other ISO 646 versions also replace backslash with other characters, including , Ö, Ø, ç and Ñ, leading to similar problems, though with less lasting impact compared to the yen sign.
RFC 1345 suggests as a unique two-character mnemonic that may be used in internet standards as "a practical way of identifying character, without reference to a coded character set and its code in coded character set".