Using Variables inside a variable in a batch

August 3, 2010 at 06:16:23
Specs: Windows 7, Quad Core i7, 12gb ram
Hi,

I am trying to use a variable inside of a variable in a batch file so for example:

set var1=this is variable one
set var2=variable 2 is %var1%

any ideas on how I can have var2 read var1?

Simon


See More: Using Variables inside a variable in a batch

Report •


#1
August 3, 2010 at 06:25:33
To explain more on what I am doing here is a sample of my script I have stared our details I do not want to share.

the script is meant to ask the user for a username then it writes a bunch of script to another batch file, once this other batch file is run it will download a file from the website and upload to another website.

however it is returning syntax errors when I try to add the script and the users username to the batch file.

I think it may be because in the script it is adding it calls to variables that are not meant to be called to on this file for example %temp% shouild be writing to the .bat file as text and not call to a variable
:USER
cls && Color F1
echo.
echo Please Enter This Websites Login Username
set /p Username= Here -^>
cls && Color 1f
echo.
echo %Username%

:Make Script
set line1=::---Start download---
set line2=@echo off
set line3=COLOR f2
set line4=setlocal
set line5=::Variables
set line6=set f=%temp%\ftpc.txt
set line7=::Compose ftp commands file
set line8=echo open %IP%>>%f%
set line9=echo user %Username% %Password%>>%f%
set line10=echo binary>>%f%
set line11=echo cd /******/********>>%f%
set line12=echo prompt>>%f%
set line13=echo mget *.occ>>%f%
set line14=echo mget *.ord>>%f%
set line15=echo mdel *.occ>>%f%
set line16=echo mdel *.ord>>%f%
set line17=echo bye>>%f%
set line18=::Execute ftp command
set line19=::Use "-d" key for verbose output
set line20=ftp -n -d -s:%f%
set line21=::Cleanup
set line22=del /f /q %f%
set line23=endlocal
set line24=::---End download---
set line25=::---Start upload---
set line26=@echo off
set line27=COLOR f2
set line28=setlocal
set line29=::Variables
set line30=set f=%temp%\ftpc.txt
set line31=::Compose ftp commands file
set line32=echo open ftp.*********.co.uk>>%f%
set line33=echo user ****** **********>>%f%
set line34=echo binary>>%f%
set line35=echo cd /*****/********>>%f%
set line36=echo prompt>>%f%
set line37=echo mput *.occ>>%f%
set line38=echo mput *.ord>>%f%
set line39=echo bye>>%f%
set line40=::Execute ftp command
set line41=::Use "-d" key for verbose output
set line42=ftp -n -d -s:%f%
set line43=::Cleanup
set line44=del /f /q %f%
set line45=endlocal
set line46=::---End upload---

:Make New Site
prompt
cls && Color F1
echo Adding New Website to Script
echo %line1% >>Prepare Import.cmd
echo %line2% >>Prepare Import.cmd
echo %line3% >>Prepare Import.cmd
echo %line4% >>Prepare Import.cmd
echo %line5% >>Prepare Import.cmd
echo %line6% >>Prepare Import.cmd
echo %line7% >>Prepare Import.cmd
echo %line8% >>Prepare Import.cmd
echo %line9% >>Prepare Import.cmd
echo %line10% >>Prepare Import.cmd
echo %line11% >>Prepare Import.cmd
echo %line12% >>Prepare Import.cmd
echo %line13% >>Prepare Import.cmd
echo %line14% >>Prepare Import.cmd
echo %line15% >>Prepare Import.cmd
echo %line16% >>Prepare Import.cmd
echo %line17% >>Prepare Import.cmd
echo %line18% >>Prepare Import.cmd
echo %line19% >>Prepare Import.cmd
echo %line20% >>Prepare Import.cmd
echo %line21% >>Prepare Import.cmd
echo %line22% >>Prepare Import.cmd
echo %line23% >>Prepare Import.cmd
echo %line24% >>Prepare Import.cmd
echo %line25% >>Prepare Import.cmd
echo %line26% >>Prepare Import.cmd
echo %line27% >>Prepare Import.cmd
echo %line28% >>Prepare Import.cmd
echo %line29% >>Prepare Import.cmd
echo %line30% >>Prepare Import.cmd
echo %line31% >>Prepare Import.cmd
echo %line32% >>Prepare Import.cmd
echo %line33% >>Prepare Import.cmd
echo %line34% >>Prepare Import.cmd
echo %line35% >>Prepare Import.cmd
echo %line36% >>Prepare Import.cmd
echo %line37% >>Prepare Import.cmd
echo %line38% >>Prepare Import.cmd
echo %line39% >>Prepare Import.cmd
echo %line40% >>Prepare Import.cmd
echo %line41% >>Prepare Import.cmd
echo %line42% >>Prepare Import.cmd
echo %line43% >>Prepare Import.cmd
echo %line44% >>Prepare Import.cmd
echo %line45% >>Prepare Import.cmd
echo %line46% >>Prepare Import.cmd


Report •
Related Solutions


Ask Question