Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Shell


From   Neil Shephard <nshephard@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Shell
Date   Fri, 6 May 2005 10:15:42 +0000

On 5/6/05, Hans J. Baumgartner <hbaumgartner@diw.de> wrote:
> Dear statalist,
> 
> I am using Stata8 on a Unix machine.
> 
> I am using the a shell to erase some files, but while doing so Stata does
> not find the end of the loop. Why?
> 
> Example
> 
> foreach x in ? {
>         do something
>         ! rm ${temp}/*.*
> }
> 
> Stata does not read the closing bracket.
> 

Stata's not seeing the end of the loop becuase it see '/*' as the
start of a comment section and anything that follows is ignored until
there is a closing '*/'

I've encountered this before, and couldn't work out any sort of
general solution.  I resolved the problem by replacing *.* with a
small amount of text that was common to the leading part of the
filename.  This may require you to slightly modify the do-file that
you are calling within the loop, so that temporary files carry a
prefix.  For example...

foreach x in ?{
   do something
   !rm ${temp}/_*.*
}

...would workaround this problem.

I guess you could escape the forward slash that follows the leading
bracket, but I can't find anything, and using the backslash to escape
it (i.e. !rm ${temp}\/*.*) does not work.

If anyone knows how to work around this I'd be interested to know.

HTH's & thanks in advance

Neil

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index