Hopefully "ScriptingTipsAndTricks" helps you with your batch file or vbscript scripting :-)
[Bottom][Contents][Prev]: Transfering (PIPING) Data Between Programs[Next]: 64 & 32 Bit Windows Operating System
\->Introduction->Special or Difficult Characters

Special or Difficult Characters

The following characters have special meaning and may need careful handling in your batch files:

Character Details
| A single vertical bar character (above "\" on keyboard) is used to indicate piping of one programs output into another.
< and > These two characters indicate redirection. ">>" means append to the file you are directing to.
& A single ampersand character is used to separate multiple commands on a single line.

This also allows it to be used as follows:

set EndsWithFiveSpaces=Something     &rem The 5 spaces before the ampersand are significant

It is also used in redirection, for example "2>&1" means send stderr output to the same place that stdout is going to.

^ The "hat" character is used to escape the "|", "<", ">" and "&" characters if required (it can also be used to escape itself).

This will only be required if they are not within double quotes:

ECHO This ^& that
ECHO "This & that"
ECHO "This & that" ^& This Again

If you use a hat when its not required it will be kept so you need to be careful.

* The asterisk character can be used in the "SET" command but it has special meaning there and so is the only difficult character for that particular command :-)

The "ReplaceAsterisks() example shows how you can replace this character if required.

% (percent)
and
! (exclamation mark)
These characters are used to perform parameter and environment variable expansion (retrieval).

The ! character only has special meaning when "delayed expansion (ENABLEDELAYEDEXPANSION)" is on. This can be very handy if you are passed the name of a variable and you wish to obrain its contents.

To escape "%" use two ("%%) and for "!" use "^!" when within double quotes otherwise "^^!" :-)

@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set Something=This is the value

set VarName=Something
echo %VarName% = !%VarName%!

echo I want to display this: "%%" and this: '%%'
echo I want to display this: "^!" and this: '^^!'


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: Transfering (PIPING) Data Between Programs[Next]: 64 & 32 Bit Windows Operating System


ScriptingTipsAndTricks© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Sunday September 07 2014 at 12:50pm
Visit ScriptingTipsAndTricks's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.