| 1. |
Solve : Setting variable in nested loops? |
|
Answer» Hi, Yesterday i got stuck in a very disgusting problem.Imagine how the interpreter feels. From experience, the best way to debug batch files is one line at a time using ECHO to check the validity of the variables as you go. Code: [Select]for /f "tokens=2 delims=:" %%a in ('cleartool pwv ^| grep -i "Working directory view" ') do echo %%a Once you satisfied that %%a has a valid value you can move on: Code: [Select]for /f "tokens=1-4 delims=_" %%i in ('echo %%a ^| sed -e "s/ //g" ') do echo %%i %%J %%k %%l Specific to your code, where was CCASE_TOOL_SERVER set? Being inside a FOR, try using double % around the CCASE_TOOL_SERVER. Unless you are getting paid by the word, there are any number of script languages (vbscript, jscript, perl, python, rexx) that would make your life easier. All but Rexx are free and vbscript and jscript are already installed on Windows MACHINES. Use the best tool for the job. Good luck. 8-) I don't have some of these utilities (MKS Toolkit :-?) on my system so I couldn't test your code.To test it you don't need any utilites, Just put anything in the for loop and if statement. The biggest dilema came in the line of set: I tried: echo set ... This was perfect. The only problem was it didn't get registered. What i am guessing right now is that there is an issue with variables when the nesting is big. I had a similar issue in one more of my mails.Quote To test it you don't need any utilites, Just put anything in the for loop and if statement. Not quite true, as batch language is largely dependent on the data and the FOR instruction utilizes patterns when parsing. Unless I lost my ability to count, are you not missing a close paren at the end of your code? Assuming %%a and %%l have valid values and the IF statement is true, try calling the SET statement. No guarantees of course, but sometimes trial and error is the best way to go. I'm still unclear why you find it necessary to create such complex nested IF's and FOR's. I've always found the Keep It Simple Stupid (KISS) method to be quite helpful. The goal is to produce results, not choke the interpreter. Good luck. 8-) Yes, From now onwards i am trying to do without nested loops. By the way, I call it Keep it Short & Simple ( My KISS ) |
|