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

Re: st: Shell

From   Neil Shephard <[email protected]>
To   [email protected]
Subject   Re: st: Shell
Date   Fri, 6 May 2005 10:15:42 +0000

On 5/6/05, Hans J. Baumgartner <[email protected]> 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


*   For searches and help try:

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