Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows BATCH script error - do ( was unexpected at this time

Tags:

batch-file

I try to run a simple batch script as shown below. Basically I want to visit each sub-directory in a given directory and run a gmake command.

echo %USER_DEF_VAR%
cd %USER_DEF_VAR%\topLevelDir
for /D %G in ("%USER_DEF_VAR%\topLevelDir\*") do ( 
cd %G
gmake clean
gmake 
)

If I run this script on a command line, it works fine. But when I put this in a .bat script it throws me an error saying

do ( was unexpected at this time.

I have tried removing spaces wherever possible as suggested here - nested For loop in batch file error: Do was unexpected at this time

I'm still facing the same issue.

like image 340
Kelly Avatar asked Mar 24 '23 19:03

Kelly


1 Answers

In a batch script you have to double the %:

for /D %%G in ("%USER_DEF_VAR%\topLevelDir\*") do ( 
cd "%%~G"
...
)
like image 177
Endoro Avatar answered Apr 06 '23 08:04

Endoro