variable inside for-loop( batch )
|
Original Message
|
Name: taiwf
Date: September 22, 2005 at 17:58:53 Pacific
Subject: variable inside for-loop( batch )OS: win2kCPU/Ram: p4 celeron/512Mb |
Comment: I am try to access a environmental variable i SET inside the batch for loop. But i can't seem to acess it even tho its actually already existed (i pause the forloop and test it on anther cmd screen). Can anyone please help me about it? Below is the script. :: I name my usb hard disk with bracket, ie.(hard-disk-Name) ::----------------------- for /f "token=2 delmis=(*)" %%A IN ('vol e: f: g: 2^>NUL') do ( SET hd_name=%%A echo %hd_name% ) ::-------------------------
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: Mechanix2Go
Date: September 22, 2005 at 20:38:58 Pacific
Subject: variable inside for-loop( batch ) |
Reply: (edit)I couldn't make yours work, so I re-wrote it. Note that the variable is NOT available in a different command shell. HTH ::::::::: @echo off for /f "tokens=*" %%A IN ('vol c: e: u: ^|find "drive"') do call :sub1 %%A goto :eof :sub1 SET hd_name=%6 echo %hd_name% goto :eof ::::::::::::::: If at first you don't succeed, you're about average.M2
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: taiwf
Date: September 22, 2005 at 22:37:38 Pacific
Subject: variable inside for-loop( batch ) |
Reply: (edit)I think the problem is whenever i try to do arithmatic inside () , it just won't work! I try this and somehow the line outside bracket give me correct answer and inside 1+1 always give me 1 not 2... SET ROT_COUNTER=1 if %ROT_COUNTER% LEQ 2 ( SET /a ROT_COUNTER=%ROT_COUNTER%+1 echo "ROT_counter less or equal to 2" echo %ROT_COUNTER% ) else ( SET /a ROT_COUNTER=1 echo %ROT_COUNTER% ) SET /a ROT_COUNTER+=1 echo %ROT_COUNTER% SET ROT_COUNTER=
Report Offensive Follow Up For Removal
|
Use following form to reply to current message: