I have a batch file that is scanning a file URLs.txt and for each url run it and download the file. The issue I have is the environment variable within the FOR loop. I am using cat, sed and awk to get the last two parts of the the url so I can provide the filename. The issue is the environment variable is never updated after the first run. I can see that tmp2.txt just updated correctly for every url, but the batch file is not updating outfile and thus I keep overwriting the first file.
I tried to simplify the batch file for a test and any variable within a for loop never seems to update.
@echo off
setlocal enabledelayedexpansion
for /F "tokens=*" %%A in (URLs.txt) do (
echo %%A > tmp.txt
cat tmp.txt | sed "s/\(.*\)\//\1_/" | awk -F "/" "{print $NF}" > tmp2.txt
set /p outfile=<tmp2.txt
echo Varible A
echo %%A
echo.
echo Varible outfile
echo %outfile%
call curl.exe -o %outfile% -u username:password --insecure %%A
pause
)
Why is environment variable outfile not updated within FOR loop?