[SOLVED]set variable=set variable= not expected at this time

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

[SOLVED]set variable=set variable= not expected at this time

#1 Post by Ed Dyreen » 19 Jul 2011 21:03

'
Dear Mr.DOS; please expect the unexpected, at any time. 8)

input:

Code: Select all

set $LF=^


:: Two empty lines are neccessary

set ^"$n1c=^^^%$LF%%$LF%^%$LF%%$LF%^^"

set ^"FileOpen=( %$n1c%

   set ^^^"RULE=( ^^^ %$n1c%

      you can do it, please Mr.DOS ^^^ %$n1c%

   )^" %$n1c%
)"
::
%FileOpen%
set FileOpen
set RULE
want:

Code: Select all

FileOpen=(
   set ^"RULE=( ^
      you can do it, please Mr.DOS ^
   )"
)

RULE=( you can do it, please Mr.DOS )
output:

Code: Select all

FileOpen=(

        set ^"RULE=( ^

                you can do it, please Mr.DOS ^

        )"
)_
"  niet verwacht op dit moment.
I would like to use continuations on the internal macro, so it's a bit more readable and easier to debug...

ps: If possible I would even want to see linefeeds on the internal macro :)

Code: Select all

RULE=(
        you can do it, please Mr.DOS
)
For the ps request I will probably need:

Code: Select all

set ^"$n2=^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%"
But then I first need to get my first request working...

Phoe, I'm so tired, I'm going to hibernate, see you guys tomorrow :wink:
Last edited by Ed Dyreen on 23 Jul 2011 02:28, edited 1 time in total.

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: set variable=set variable=was not expected at this time

#2 Post by dbenham » 19 Jul 2011 22:32

Well the obvious solution (with a jeb :wink: ) is:

Code: Select all

@echo off
set $LF=^


:: Two empty lines are neccessary
set $n2c=^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%^^
set $n1c=^^^%$LF%%$LF%^%$LF%%$LF%^^

set FileOpen=( %$n1c%
   rem demonstrate single spacing%$n1c%
   rem demonstrate single spacing%$n1c%
   set RULE=( %$n2c%
      you can do it, please Mr.DOS %$n2c%
   ^^) %$n1c%
   rem demonstrate single spacing%$n1c%
   rem demonstrate single spacing%$n1c%
)

::and now we test it
%FileOpen%
set FileOpen
set RULE

Output:

Code: Select all

FileOpen=(
   rem demonstrate single spacing
   rem demonstrate single spacing
   set RULE=( ^

      you can do it, please Mr.DOS ^

   ^)
   rem demonstrate single spacing
   rem demonstrate single spacing
)
RULE=(
      you can do it, please Mr.DOS
   )


I couldn't figure out how to keep the enclosing quotes, but they were not helping anyway.

I don't understand why you introduce extra line feeds within your macro definitions :?: It seems to work either way :? , but I find the code much easier to read in the more compressed form.

Dave Benham

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: set variable=set variable=was not expected at this time

#3 Post by Ed Dyreen » 20 Jul 2011 09:10

'
You cheated :mrgreen:

You removed the quotes, I know the quotes aren't helping, they are actually making things more difficult. But it's all about standardization either I always quote, or I'll never quote...

You chose the easy solution ( remove quotes ), this is the whole point.
I'm trying to figure out how I can keep them.

I believe it's possible, you believe otherwise ? Am I wasting time here ? :)

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: set variable=set variable=was not expected at this time

#4 Post by dbenham » 20 Jul 2011 09:53

I wouldn't be so bold to say it can't be done...

But I wouldn't waste my time trying to make it work when there is simpler syntax that works.

My standard is to NOT quote my macro definitions, but don't chastise me if you find a post where I did :mrgreen:

Dave Benham

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: set variable=set variable=was not expected at this time

#5 Post by Ed Dyreen » 20 Jul 2011 12:42

'
JACKPOT :mrgreen:

Code: Select all

@echo off
set $LF=^


:: Two empty lines are neccessary
set $c1=^^
set $c2=^^^^
set $n1=^^^%$LF%%$LF%^%$LF%%$LF%
set $n2=^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%
set $n1c=^^^%$LF%%$LF%^%$LF%%$LF%^^
set $n2c=^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%^^

set ^"FileOpen=( %$n1c%

   set ^^^"RULE=( %$n2c%
%$c2%
      you can do it, please Mr.DOS %$n2c%
%$c2%
   ^^)^" %$n1c%
)"
%FileOpen%
set FileOpen
set RULE

pause
exit /b
The %$c2% position is unfortunate, ( does not allow indention )
but adding tabs or moving it to the previous line will break the macro.

Well that's my next objective, but I fear impossible,
there is just no way of making it look more "beautiful" AND keeping the quotes...

output:

Code: Select all

FileOpen=(

        set ^"RULE=( ^

^               you can do it, please Mr.DOS ^

^       ^)"
)
RULE=(
                you can do it, please Mr.DOS
        )
Druk op een toets om door te gaan. . .
Last edited by Ed Dyreen on 20 Jul 2011 19:38, edited 3 times in total.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: set variable=set variable=was not expected at this time

#6 Post by Ed Dyreen » 20 Jul 2011 19:31

'
Now it's that delayed thingy causing problems again, I like delayed enabled for this macro.

Code: Select all

@echo off
set $LF=^


:: Two empty lines are neccessary
set $c1=^^
set $c2=^^^^
set $n1=^^^%$LF%%$LF%^%$LF%%$LF%
set $n2=^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%
set $n1c=^^^%$LF%%$LF%^%$LF%%$LF%^^
set $n2c=^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%^^
set "$ED.Path=somepath"

setlocal enabledelayedexpansion

set FileOpen=( %$n1c%
   set RULE=( %$n1c%
      !$ED.Path! %$n1c%
   ^^) %$n1c%
)

set FileOpen
%FileOpen%
set RULE

echo.endoftest
pause
exit
Now that I did not expect, yes I know jeb; The obvious :)

It would be very easy though, only if I knew where this leading space is coming from :shock:

Code: Select all

prompt $

@echo on
set FileOpen=(%$n1c%
set RULE=!$ED.Path!^^^^^^^^%$n1c%
some%$n1c%
)
output:

Code: Select all

set FileOpen=(
set RULE=!$ED.Path!^^^^
some
)

set FileOpen
FileOpen=(
set RULE=somepath^^
some
)

(
set RULE=somepath^
_some
)
some wordt niet herkend als een interne
of externe opdracht, programma of batchbestand.

set RULE
RULE=somepath^

echo.endoftest
endoftest

pause
Druk op een toets om door te gaan. . .
The underscore represents a leading space.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: set variable=set variable=was not expected at this time

#7 Post by Ed Dyreen » 20 Jul 2011 21:00

'
This is the best I could do with delayed enabled, but it's disappointing, it looks even worse now, it works though.

Code: Select all

@echo off
set $LF=^


:: Two empty lines are neccessary
set $c1=^^
set $c2=^^^^
set $n0=^%$LF%%$LF%
set $n1=^^^%$LF%%$LF%^%$LF%%$LF%
set $n2=^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%
set $n1c=^^^%$LF%%$LF%^%$LF%%$LF%^^
set $n2c=^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%^^
set "$ED.Path=somepath"

setlocal enabledelayedexpansion

set ^"FileOpen=( %$n1c%

   set ^^^^^"RULE=( ^^^!$n0^^^!^^^^%$n2c%
%$c2%
      ^^^^^>nul 2^^^^^>^^^^^&1 reg delete "!$ED.Path!" hello^^^!$n0^^^!^^^^%$n2c%
%$c2%
   ^^^^)^" %$n1c%
)"

set FileOpen
%FileOpen%
set RULE

echo.endoftest
pause
exit
output:

Code: Select all

FileOpen=(

        set ^"RULE=( !$n0!^

           ^>nul 2^>^&1 reg delete "somepath" hello!$n0!^

        ^)"
)
RULE=(

           >nul 2>&1 reg delete "somepath" hello

        )
endoftest
Druk op een toets om door te gaan. . .
I wish I could clean it up, because this is just ugly, makes me a little sad actually :(

I tried your advice not to quote but it makes little difference ( because one can expect I will need to quote internally like on the reg delete that I used as example ) .

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: set variable=set variable=was not expected at this time

#8 Post by Ed Dyreen » 21 Jul 2011 10:35

'
I don't understand why you introduce extra line feeds within your macro definitions :?: It seems to work either way :? , but I find the code much easier to read in the more compressed form.

Ok then, let's suppose I did it your way &defined RULE on a single line.
Let's suppose I made a syntax error inside the RULE definition.

I won't be using linefeeds;
What this means is that I will have to scroll from the left to the right a couple of hundred characters !

I won't be using indention;
every time I encounter a '(' I will have to memorize it !

Additionally I would have to cut the entire line, make it shorter and paste it again ( hoping I did it correctly ).

So which one would be easiest to debug :?:

Code: Select all

set ^"FileOpen=( %$n1c%

  set ^^^^^"RULE=( ^^^!$n0^^^!^^^^%$n2c%
%$c2%
    ^^^^^>nul 2^^^^^>^^^^^&1 reg delete "^^^!$ED.Path^^^!" /v "FileOpen" /f ^^^^^&^^^^^&( ^^^!$n0^^^!^^^^%$n2c%
%$c2%
      ^^^^^>nul 2^^^^^>^^^^^&1 reg query "^^^!$ED.Path^^^!" /v "FileOpen.%%~^^^!" ^^^^^&^^^^^&( ^^^!$n0^^^!^^^^%$n2c%
%$c2%
        set /a ù = 1 ^^^!$n0^^^!^^^^%$n2c%
%$c2%
      ^^^^^) ^^^^^|^^^^^|( ^^^!$n0^^^!^^^^%$n2c%
%$c2%
        set /a ù = 0 ^^^!$n0^^^!^^^^%$n2c%
%$c2%
        for /f "tokens=1-4" %%%%b in ( ^^^!$n0^^^!^^^^%$n2c%
%$c2%
          " "%E7%!$ED.Path%E7%!" "FileOpen.%%~%E7%!" "REG_SZ" "%E7%^^^^!Sub.^^^!Sub.Depth^^^!.Name%E7%^^^^!" " ^^^!$n0^^^!^^^^%$n2c%
%$c2%
        ^^^^^) do %E7%^^^^!ERR.Chk.RegWrite.TokenSTR%E7%^^^^! ^^^^^>nul ^^^^%$n1c%
%= =%
      ^^^^^) ^^^!$n0^^^!^^^^%$n2c%
%$c2%
      for /f "tokens=1-4" %%%%b in ( ^^^!$n0^^^!^^^^%$n2c%
%$c2%
        " "%E7%!$ED.Path%E7%!" "FileOpen" "REG_SZ" "Ready" " ^^^!$n0^^^!^^^^%$n2c%
%$c2%
      ^^^^^) do %E7%^^^^!ERR.Chk.RegWrite.TokenSTR%E7%^^^^! ^^^^^>nul ^^^!$n0^^^!^^^^%$n2c%
%$c2%
    ^^^^^) ^^^^^|^^^^^|set /a ù = 1 ^^^!$n0^^^!^^^^%$n2c%
%$c2%
    if %E7%^^^^!ù%E7%^^^^! neq 0 ^^^^%$n1c%
%= =%
  ^^^^^)^" %$n1c%

  !§LOOPIf! /Eval: "RULE" %$n1c%

) ^&( %$n1c%

  !@n2echo! FileOpen : '%%~^^^!' [OK] %$n1c%
)"

set FileOpen
for %%! in ( UserVARs ) do %FileOpen%
pause
set RULE

%@endoftest%
or:

Code: Select all

for %%? in ( FileOpen ) do    set "%%~?=set "RULE=^>nul 2^>^&1reg delete "!$ED.Path!" /v "FileOpen" /f ^&^&( ^>nul 2^>^&1 reg query "!$ED.Path!" /v "FileOpen.%%~^^^!" ^&^&set /a ù = 1 ^|^|( set /a ù = 0    ^&    for /f "tokens=1-4" %%b in ( " "!$ED.Path!" "FileOpen.%%~^^^!" "REG_SZ" "%E7%!Sub.^^^!Sub.Depth^^^!.Name%E7%!" " ) do    ^^^!ERR.Chk.RegWrite.TokenSTR^^^! %()% ^>nul ^&echo.^>nul )    ^&for /f "tokens=1-4" %%b in ( " "!$ED.Path!" "FileOpen" "REG_SZ" "Ready" " ) do ^^^!ERR.Chk.RegWrite.TokenSTR^^^! %()% ^>nul ^&echo.^>nul    ) ^|^|set /a ù = 1 ^&if %E7%!ù%E7%! neq 0 " ^&%LOOPIf% /Eval: "RULE"    ^&( echo. ^&echo. ^&set /p "= FileOpen : '%%~^^^!' [OK]"    <nul ) "

This is why I was hammering so much on the linefeeds.

We need to focus on debugging ben, we need linefeed AND indention AND delayed ( the ability to include other macro's )

I hope WHY has become clear to you now ( answering my own posts is a bit boring :) ).

This is the best I can do, if you see possibilities for making it look even nicer...

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: set variable=set variable=was not expected at this time

#9 Post by dbenham » 21 Jul 2011 11:31

Ed Dyreen wrote:Ok then, let's suppose I did it your way &defined RULE on a single line.
You completely misunderstood my question :lol:

I understand why you want your internal macro to have multiple lines.

I was curious why you write your macros like this:

Code: Select all

@echo off
set $LF=^


:: Two empty lines are neccessary
set $n1c=^^^%$LF%%$LF%^%$LF%%$LF%^^

set SimpleMacro1=( %$n1c%

  echo Line1%$n1c%

  echo Line2%$n1c%

  echo Line3%$n1c%
)

::and now we test it
set SimpleMacro1
%SimpleMacro1%
Output:

Code: Select all

SimpleMacro1=(

  echo Line1

  echo Line2

  echo Line3
)
Line1
Line2
Line3

Whereas I would write it like this:

Code: Select all

@echo off
set $LF=^


:: Two empty lines are neccessary
set $n1c=^^^%$LF%%$LF%^%$LF%%$LF%^^

set SimpleMacro2=( %$n1c%
  echo Line1%$n1c%
  echo Line2%$n1c%
  echo Line3%$n1c%
)

::and now we test it
set SimpleMacro2
%SimpleMacro2%
Output:

Code: Select all

SimpleMacro2=(
  echo Line1
  echo Line2
  echo Line3
)
Line1
Line2
Line3


Both macros give the same result, but I find the extra line feeds in your style distracting. It also takes up twice the amount of screen space, which becomes an issue when tracking logic of large macros.

It's not a big deal - just a matter of style. I was just wondering if there was a reason why you adopted that style :?:

Dave Benham

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: set variable=set variable=was not expected at this time

#10 Post by Ed Dyreen » 21 Jul 2011 14:15

'
You could also ask me why I always use '<LF> or ☺<LF> before responding...

This is not worth the discussion, such a detail, I'll tell you why:

set macro (

These strings
deal with things that
relate to each other

this has nothing
to do with the
above block

)

O boy :roll:

Post Reply