Octopuss Posted January 12, 2015 Share Posted January 12, 2015 My head is about to explode. Despite writing it just like it says in help, it doesn't work.if exist d:\win7\boot\cs-cz\nul (set language=cz) else set language=if %language%==cz (copy e:\unattended\AeroNoBackground-cz.theme d:\win7\sources\$OEM$\$$\resources\themes\AeroNoBackground.theme) else copy e:\unattended\AeroNoBackground.theme d:\win7\sources\$OEM$\$$\resources\themes When I run it, I always get an error saying "( was unexpected at this time.". I don't get it. Please help. Link to comment Share on other sites More sharing options...
bphlpt Posted January 12, 2015 Share Posted January 12, 2015 Try changingif %language%==cz (toif [%language%]==[cz] (orif "%language%"=="cz" (and/or changeelse set language=toelse set language=notczWhat I think you are running into was if language was empty or null or not defined, ie "else set language=", then your "if %language%==cz (" became "if ==cz (" and the syntax was just wrong and "( was unexpected at this time.". I hope that makes sense.Cheers and Regards Link to comment Share on other sites More sharing options...
jaclaz Posted January 12, 2015 Share Posted January 12, 2015 BUT you can also remove altogether the condition: if exist d:\win7\boot\cs-cz\nul (set language=czcopy e:\unattended\AeroNoBackground-cz.theme d:\win7\sources\$OEM$\$$\resources\themes\AeroNoBackground.theme) else (set language=copy e:\unattended\AeroNoBackground.theme d:\win7\sources\$OEM$\$$\resources\themes) jaclaz Link to comment Share on other sites More sharing options...
bphlpt Posted January 12, 2015 Share Posted January 12, 2015 Very true, and a better solution, of course. But at least now he knows why his script wasn't working. Cheers and Regards Link to comment Share on other sites More sharing options...
Octopuss Posted January 12, 2015 Author Share Posted January 12, 2015 (edited) I got it. It was this: else set language=. After changing it to set language="", it worked. Apparently what I originally did didn't set the variable empty, but rather removed it alltogether (which I did notice when simply typing set, but didn't understand what was going on). Jaclaz, you are probably right, but I didn't mention there was one more (might be even more in future if I bother with this stuff further) similar copy operation below. I did it like this to save a few lines. I wish I wasn't so dumb when it comes to anything even remotely related to scripting/programming, but I just can't wrap my brains around it. No sh.. I failed even at such simple thing as Turbo Pascal 20 years ago Edited January 12, 2015 by Octopuss Link to comment Share on other sites More sharing options...
bphlpt Posted January 12, 2015 Share Posted January 12, 2015 I'm not completely sure, but if you don't need the "language" variable anywhere else I think you could also simplify it even further with: if exist d:\win7\boot\cs-cz\nul (set language=-cz) else (set language=)copy e:\unattended\AeroNoBackground%language%.theme d:\win7\sources\$OEM$\$$\resources\themes\AeroNoBackground.theme If you do need the language variable elsewhere you could also change the AeroNoBackground-cz.theme to AeroNoBackgroundcz.theme and use: if exist d:\win7\boot\cs-cz\nul (set language=cz) else (set language=)copy e:\unattended\AeroNoBackground%language%.theme d:\win7\sources\$OEM$\$$\resources\themes\AeroNoBackground.theme In any case, it is always better to enclose both sides of your compare tests with something and not leave them "naked" like you did - if %language%==cz ( - just to prevent potential problems or misunderstandings. Cheers and Regards Link to comment Share on other sites More sharing options...
Octopuss Posted January 12, 2015 Author Share Posted January 12, 2015 (edited) Ha, that's a good idea. I'll experiment a bit with it. It's largely irrelevant, but I always like to do things in the cleanest possible way. Edited January 12, 2015 by Octopuss Link to comment Share on other sites More sharing options...
Octopuss Posted January 12, 2015 Author Share Posted January 12, 2015 I have another stupid question (and I feel really dumb this time). :ntbset /p brand="Manufacturer's name: "if %brand%=="" goto :noinputgoto :start:noinputecho.echo. No input. Try again.goto :ntb No matter what I type, it always ends up with "goto was unexpected at this time". I read some documentation about the various commands several times and still don't understand why it doesn't work. Link to comment Share on other sites More sharing options...
jaclaz Posted January 12, 2015 Share Posted January 12, 2015 Hmmm. What about::ntbset /p brand=Manufacturer's name: if "%brand%"=="" echo.&echo. No input. Try again.&goto :ntbgoto :startjaclaz Link to comment Share on other sites More sharing options...
bphlpt Posted January 12, 2015 Share Posted January 12, 2015 (edited) I have another stupid question (and I feel really dumb this time). You should. In any case, it is always better to enclose BOTH sides of your compare tests with something ... just to prevent potential problems or misunderstandings. Personally, I prefer using square brackets [ ] rather than quotes " ", but both will work. A couple of references I use are http://ss64.com/nt/if.html and http://www.robvanderwoude.com/if.php From the second one: When comparing strings, make sure neither of them is empty or contains spaces only (both leading and trailing spaces are ignored).Empty strings can be prevented easily by adding some meaningless but non-empty string at both sides of the equal sign:IF X%1==X/? GOTO HelpscreenEven if no parameter is given (in which case %1 is an empty string) the string before the equal sign won't be empty.A commonly used way to prevent empty strings is enclosing them in either quotes or (square) brackets:IF "%1"=="/?" ... orIF [%1]==[/?] ...If %1 itself may contain quotes you're in trouble: if %1 equals "/?" including the quotes, IF "%1"=="/?" ... evaluates to IF ""/?""=="/?" ... which will generate an error message.As usual, jaclaz beat me with his post. As a slight alternative to his code, this also works the same way::ntbset /p brand="Manufacturer's name: "if not defined brand echo.&echo. No input. Try again.&goto :ntb:startOf course for both of our codes, no error checking is provided that a valid manufacturer has been entered. If the user enters nonsense, or even just a single space, then both codes will accept that just fine. (Unless some special problematic characters are entered, but that's a whole different set of problems.)Cheers and Regards Edited January 12, 2015 by bphlpt Link to comment Share on other sites More sharing options...
jaclaz Posted January 12, 2015 Share Posted January 12, 2015 Well, usually 1/10th of the time is used to write the batch and the remaining 8/10th's are used to prevent the user from entering nonsense. Before you ask, the 1/10th missing in the above is wasted in looking at squirrels or similar. jaclaz Link to comment Share on other sites More sharing options...
Octopuss Posted January 12, 2015 Author Share Posted January 12, 2015 (edited) Hmmm. What about::ntbset /p brand=Manufacturer's name: if "%brand%"=="" echo.&echo. No input. Try again.&goto :ntbgoto :startjaclazOk... what does the & char do, and why does this work and what I did doesn't? Since I posted the question I tried it with the quotes, like so P.S. These are all stupid little scripts I use for myself when I occasionally prepare a Windows image, so there's no need for any user stupidity checks (OR maybe is, lol). edit:If bold and red font wasn't enough... ok, "%brand%" is what it needed. I don't get it though!! Nowhere I looked did it say you have to compare strings like this. Grr.Oh well.This works::ntbset /p brand="Manufacturer's name: "if "%brand%"=="" (echo. No input. Try again.goto :ntb) else (goto :start) Edited January 12, 2015 by Octopuss Link to comment Share on other sites More sharing options...
Octopuss Posted January 13, 2015 Author Share Posted January 13, 2015 (edited) I am starting to think the whole thing is bugged. if "%type%"=="some string" (...several copy lines) This didn't work at all until I removed the quotes around %type%!!! Edited January 13, 2015 by Octopuss Link to comment Share on other sites More sharing options...
bphlpt Posted January 13, 2015 Share Posted January 13, 2015 Too little information. What are the possible values of "some string"? Can you share both the section of code where %type% is set and the section where it is tested and used? Cheers and Regards Link to comment Share on other sites More sharing options...
Octopuss Posted January 13, 2015 Author Share Posted January 13, 2015 (edited) I thought comparing strings is always the same, no? Well this is the (almost, edited the actual copy/whatever operations out) whole thing:choice /c:123 /m "Is this a: (1:desktop, 2:notebook, 3:my own PC, 4:N/A) ?"if errorlevel==4 goto :startif errorlevel==3 set type="-ja"if errorlevel==2 goto :ntbif errorlevel==1 set type=""goto :start:ntbset type="-ntb"set /p brand="Manufacturer's name: "if "%brand%"=="" (echo.echo No input. Try again.echo.goto :ntb) else (goto :start):startif exist d:\win7\boot\cs-cz\nul (set language="cz") else (set language="")...copy operationsif "%language%"=="cz" (copy "e:\unattended\keyb-EN-US+CZ-QWERTZ.xml" d:\win7\sources\$OEM$\$1\install /y) else (copy "e:\unattended\keyb-EN-US+CZ-QWERTY.xml" d:\win7\sources\$OEM$\$1\install /y)if %type%=="-ja" (...more copy operations)When the .xml file is being chosen, the if works with quotes.And it doesn't at the end. It makes zero sense. A string is a string. If command is always if. Edited January 13, 2015 by Octopuss Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now