Output new batch with variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jbird123
Posts: 3
Joined: 25 Mar 2009 05:18
Location: Wales!
Contact:

Output new batch with variable

#1 Post by jbird123 » 03 Aug 2010 15:09

Im writing a batch script that creats another batch file, and inside the new batch file I need to prompt user to enter y/n. But im having trouble..

Code: Select all

echo 4. Creating new batch..
echo @echo off > "%UserProfile%\Desktop\file.cmd"
echo echo Are you sure you wish to continue? [y/n] >> "%UserProfile%\Desktop\file.cmd"
echo set /p continue= >> "%UserProfile%\Desktop\file.cmd"
echo IF NOT (%continue%)==(y) GOTO END >> "%UserProfile%\Desktop\file.cmd"
echo RMDIR "%APPDATA%\Microsoft\Windows\SendTo\test" /S /Q >> "%UserProfile%\Desktop\file.cmd"
echo msg * "test removed!" >> "%UserProfile%\Desktop\file.cmd"
echo :END  >> "%UserProfile%\Desktop\file.cmd"
echo echo done.. >> "%UserProfile%\Desktop\file.cmd"
echo pause >> "%UserProfile%\Desktop\file.cmd"
echo.


Obviously the line
echo IF NOT (%continue%)==(y) GOTO END >> "%UserProfile%\Desktop\file.cmd"
is trying to write the variable %continue% to the new batch, but it doesnt exist. I want to to output the actual string %continue% not the variable.

Tried using quotes and stuff but with no luck. Any suggestions?
Thanks!

jbird123
Posts: 3
Joined: 25 Mar 2009 05:18
Location: Wales!
Contact:

Re: Output new batch with variable

#2 Post by jbird123 » 03 Aug 2010 15:20

I've just spent ages trying to sort this, finally decided to post then fpund out for myself lol.

To output a percent (%) sign in a batch you have to type %%

so my code becomes

Code: Select all

echo IF NOT (%%continue%%)==(y) GOTO END >> "%UserProfile%\Desktop\file.cmd"

which outputs

Code: Select all

echo IF NOT (%continue%)==(y) GOTO END

Post Reply