WARNING: If you want to learn to write batch script in DOS, stop it right now! Do yourself a favor. Stop reading this tutorial. Unless your are masochist. Please consider other alternative such as Perl. DOS is a pain and the 'language' is not intuitive and not logical.
start batchfile.bat
Display string.
REM Display "This is a string." ECHO This is a string. REM Escape special character using ^ REM Display ampersand(&) ECHO ^&
SETLOCAL: Localise environment variables under SETLOCAL.
ENDLOCAL: Restore previous environment variables that are set before SETLOCAL.
@ECHO OFF REM Value1 SETLOCAL SET value=1 ECHO %value% REM Value2 SETLOCAL SET value=2 ECHO %value% REM Value3 SETLOCAL SET value=3 ECHO %value% REM Back to Value2 ENDLOCAL ECHO %value% REM Back to Value1 ENDLOCAL ECHO %value%
ECHO Hello & ECHO Hello Again
ECHO Hello && ECHO I will only run if the previous command was completed successfully.
:: This line is a comment.REM This line is also a comment @REM Adding @ in front of REM will not even show this command in the DOS prompt.
@ECHO OFF ECHO Hello1 &:: This is a comment at the end of this line. ECHO Hello2 &REM This is also a comment at the end of this line.
REM Clean Prompt line prompt $ REM Put Prompt line back to MSFT's default format prompt $p$g REM Show date and time: Sun 03/07/201013:16:23.90 <C:\WINDOWS> prompt $D $T$_$L$P$G
http://www.ss64.com/
http://www.robvanderwoude.com/news.html
http://stackoverflow.com/questions/8385454/batch-files-list-all-files-in-a-directory-with-relative-paths
Redirect application to NUL
echo a > NUL