Getting a Batch File to Ignore a Variable

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

I seem to be getting syntax errors on my script and I think it is beacause it is calling to a variable that does not exist for example

set name=Simon

set code=%script% is not %name%

however I want %script% to be read as pure text and %name% to be read as Simon is this possible?


See More: Getting a Batch File to Ignore a Variable

Report •

August 3, 2010 at 07:06:04
Yes by coding a pair of %

set code=%%script%% is not %name%

By the way I read your (long) post in DOS Forum and I guess you have to improve your batch scripting knowledge starting to learn plain DOS batch is not NT batch that is more powerful and offers more commands and options, e.g.

cls & color nn

NOT cls && that has a different meaning.

Report •

August 3, 2010 at 07:31:22
ok thats not returning any errors however it isnt inserting "%script%" into the new file it is just deleting it.

Report •

August 3, 2010 at 07:42:09
hmm im trying to find out what is going on here and it isnt that it isnt copying them over however after some parts I need "%f%" to appear for example writing:

set line9=echo user %Username% %Password%>>%%f%%

this is meant to write:

echo user simon mypass>>%f%

however it simply writes:

echo user simon mypass

any ideas on why?

Report •

Related Solutions

August 3, 2010 at 08:25:35
Because >> %f% is interpreted as a redirector for the SET command NOT part of the string.

To write a redirector inside a variable you have to "escape" it by prefixing with a caret symbol (^), i.e.

set line= %user% %pwd% ^>^> %%f%%

but this blows up other troubles when echoing the variable.

Sorry, handling special symbols in batch is a hard job and must be planned carefully as there is no general rule.

You are trying too hard for your level of knowledge.

Report •

August 3, 2010 at 08:33:22
Thanks for the advice IVO, now I am just wondering I recieved my code to upload to ftp from a guide now that line basicly connects to the ftp giving it the username and password now out of curiosity what is the ">>%f%" part actually for? and does it need to be there to upload to ftp here is the upload script I am using:

::---Start download---
@echo off

set f=%temp%\ftpc.txt

::Compose ftp commands file
echo open ftp.****>>%f%
echo user *** ***>>%f%
echo binary>>%f%
echo cd /htdocs/acatalog>>%f%
echo prompt>>%f%
echo mget *.occ>>%f%
echo bye>>%f%

::Execute ftp command
::Use "-d" key for verbose output
ftp -n -d -s:%f%

del /f /q %f%
::---End download---

Report •

August 3, 2010 at 08:36:04
hmm after looking at the above code I see %f% is creating a file to store the details perhaps I can add these into a variable such as:

set triangles=>>

then call to them in the variable like:

set line9=echo user %Username% %Password% %triangles% %%f%%

Report •

August 3, 2010 at 08:50:57
Well, from the script you posted the meaning of %f% is clear:

the ECHO sequence builds up the FTP.txt file holding the commands to automate the ftp process. Each string is echoed to %f% i.e. the ftp.txt file in the Temp directory previously set by SET F=.

That is a well known practice when a batch script creates an auxiliary command sequence.

Your troubles arise because you first set variables then echo them instead to directly write the aux order file.

I hope my explanation is clear enough.

Report •

August 3, 2010 at 08:53:43
Hi Ivo,

thankyou for the break down this has helped me to understand. I am too used to javascript and Php and as you have picked up on my knowledge of batch is at a minimal however I have to get this working. so is there any chance you could have a look at my script and explain how I could get it working?

Thanks for the help,

Report •

August 3, 2010 at 09:47:03
Send me a private message with your e-mail address or contact me by using private e-mail system ; I will replay by e-mail then you can explain what you want to achieve and send me as a text (not .bat) attachment the script you set up.

I am glad to help you, but I can't assure anything as I am very busy these days. I am surprised you want to code in batch while expert in java and php, more powerful programming tools.

Ivo Luigi Bertani
Milano - Italy

Report •

Ask Question