~ and ! for vars in batch files

August 25, 2011 at 20:51:28
Specs: Windows 7
I have questions regarding the use of ~ and ! in batch files.
It appears that in the following... (questions in line as REM)

@echo off
REM ======== set the list name and location
set ComputerList=.\ComputerList.txt
REM ======== set the new file and header in file
Echo Computername,IP Address>Final.csv
setlocal enabledelayedexpansion
REM ======== loop for the vars in the list
for /f "usebackq tokens=*" %%A in ("%ComputerList%") do (
REM ======== on the vars in the list, ping each and take token 3 and call it var b
REM ======== the shift 6 aparently escapes the pipe so it functions
for /f "tokens=3" %%B in ('ping -n 1 -l 1 %%A ^| findstr Reply') do (
REM ======== prep a new var with results of that output, then echo the results to an CSV
set IPadd=%%B
echo %%A,!IPadd:~0,-1!>>final.csv
REM ** NEED TO FIGURE OUT !IPadd:~0,-1! what the bangs do, looks like maybe local only var
REM also figure out what the tilde is for, look like it is a short cut to last output or similar...

See More: ~ and ! for vars in batch files

Report •

August 25, 2011 at 21:16:13
! denotes delayed expansion of environment variables. Enter SET /? at the command prompt for examples and explanations.

~ enter FOR /? at the command prompt for examples and explanations.

Please come back & tell us if your problem is resolved.

Report •
Related Solutions

Ask Question