Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Why do `test' and a`test' make a difference?


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Why do `test' and a`test' make a difference?
Date   Mon, 11 Feb 2013 00:20:08 +0000

See also

http://www.stata.com/support/faqs/programming/backslashes-and-macros/

for a systematic account.

Nick

On Sun, Feb 10, 2013 at 9:24 PM, Dirk Enzmann
<[email protected]> wrote:
> Thank you Nick, very helpful!
>
> And thanks to Statalist as an institution to turn to when searches such as
> -hsearch backslash-, -hsearch pathname-, -hsearch filename-, -search escape-
> or the subject index of the manual(s) do not help. I suspected an issue with
> escape characters, but didn't know where to look for help besides asking
> Statalist.
>
> With your help I could locate section 18.3.11 in [U] which explicitly warns
> Windows users about not using backslashes in pathnames. However, I still
> couldn't locate an explanation of the use of the backslash \ as an escape
> character in the manuals.
>
>
> To summarize: Whereas the use of a backslash results in
>
> ------------------------------------
> . global path = "d:\my folder\"
> . local test = "pre_"
> .
> . di "${path}`test'my name.dta"
> d:\my folder`test'my name.dta
> .
> . di "${path}a`test'my name.dta"
> d:\my folder\apre_my name.dta
> ------------------------------------
>
> the clean way of using forward slashes, instead, results in
>
> ------------------------------------
> . global path = "d:/my folder/"
> . local test = "pre_"
> .
> . di "${path}`test'my name.dta"
> d:/my folder/pre_my name.dta
> .
> . di "${path}a`test'my name.dta"
> d:/my folder/apre_my name.dta
> ------------------------------------
>
> Dirk
>
>
>> In Stata backslashes have two roles
>>
>> 1. General: As an escape character.
>>
>> 2. Specific, for Windows users so inclined: As a separator within >
>> pathnames.
>>
>> and single left quotation marks ` also have two roles
>>
>> 1. As introducing local macro references.
>>
>> 2. As literal characters, an interpretation you insist on with \`
>>
>> So
>>
>> \`test'
>>
>> is taken as a sign that for some reason for your own you are
>> protecting the ` of `test', which is why you put the \ in there.
>>
>> So, don't do that. Use forward slashes for pathname separators, even
>> in Windows. This advice is spelled out in [U] and again in
>>
>> SJ-8-3  pr0042  . . . . . . .  Stata tip 65: Beware the backstabbing >
>> backslash
>>         . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . > N.
>> J. Cox
>>         Q3/08   SJ 8(3):446--447                                 (no >
>> commands)
>>         tip to use forward slash instead of backslash for
>>         directory and file names
>>
>> Nick
>>
>> On Sun, Feb 10, 2013 at 1:18 PM, Dirk Enzmann
>>
>> > Why does the backslash as part of the global macro $path vanish (and
>>
>> > `test' is not evaluated as a local macro) when immediately combined with
>> > the local macro `test', although it does not vanish (and the content of
>> > `test' is displayed) when not immediately combined as shown in the two
>> > variants of -di- in the example below?
>> >
>> > * --- Stata example start: -----------
>> >
>> > global path = "d:\my folder\"
>> > local test = "pre_"
>> > di "${path}`test'my name.dta"
>> > di "${path}a`test'my name.dta"
>> >
>> > * --- End Stata example. ------------
>> >
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index