Welcome to The Tech 
Guide
Google
 
Web www.thetechguide.com
Geeks with attitude
Navigation
  • Home
  • How-To's
  • Tweaks
  • Hardware
  • Software
  • Games
  • Our Picks
  • Downloads
  • FAQ's
  • Forum
  • Chat
  • Tech Deals
  • Links
  • Email

  • Site News
    Our Black Friday section is now online! Click here to check it out.

    Active Discussions
    [an error occurred while processing this directive]


      

    Tutorial on Basic Windows 2000 DOS

      This Section Will Cover
    • 00. What a file is under win enviroment
    • 01. What a variable is in %win2k% batch and how to create them.
    • 02. What echo echo. @echo off does.
    • 03. What operators like > and >> and | do.
    • 04. What a ::comment is.
    • 05. What & does and how to use it &::creatively.
    • 06. What 'DIR' and 'SORT' is and does
    • 07. What a * and a ? mean to the DOS shell.
    • 08. What GOTO _is when used with :_labels, also using PING to create a delay.
    • 09. What if "statements"=="are and what they do".
    • 10. What a basic "for" loop is/does.
    • 11. How to use low interger values with variables.
    • 12. How to parse strings into substrings.
    • 13. How to echo non-echoable characters.
    • 14. How to pass %arguments to a .bat file.
    • 15. Summary

    ::This is a comment. You will read in many M$-DOS books that you can use REM which stands for remark. This is possible, however it is just 1 more byte (1 character equals 1 byte, ie, the word Hello is 5 byte's). Also it holds other limitations, just know to use :: instead of REM.

    & means, well more or less, "and do this". Or you could consider it to be a new line, either is fine. Just know that using & does NOT do 2 things at the same time. They happen in sequential order. Like in our only example so far if you wrote...

    echo "%foo%" >>some_file.txt&echo "%foo%" >>some_file.txt

    The above would echo out "Hello Batch!" 2 times everytime you run it. The & helps take care of commands you want to run on different lines, by doing it on 1 line. Although you can type the command using & on 1 line to save space, the result will be as if you entered the commands on 2 different lines. There will be 2 lines of "Hello Batch!" in some_file.txt

    Ok so you could use 2 commands, but what about comments? Well you can use & with :: and get comments on the same line. It's 2 commands, but the 2nd command is a comment so you never see it get displayed. Let's redo our current script to look like the below...

    @echo off
    SET foo=Hello Batch!
    echo.
    echo  "%foo%" &:: This is a comment on the same line.
    echo.
    ::
    ::This is a comment on its own line
    ::
    echo  Press [ENTER] to exit
    pause >nul
    You run, and it still looks the same. That's because on the line that has echo "%foo%" we put &:: to make a comment. What this does is echo out what the foo variable holds, then immediately see's the & and takes whatever else is after it on the same line and treats it like a new line. What comes next is :: so it treats it as a comment and you don't see it.

    The :: does not have to have anything after it. It can be used to create an area for comments or to ensure you have correct values when setting variables. You might want to do this if you have some comments you want to put in there that will span several lines and you want them to be seen. As you can imagine...

    ::
    ::
    ::
    ::Comment here
    ::
    ::
    ::
    is very noticeable. You won't have to hunt and dig for comments too long since they have such a noticable look.

    Of course ::&::&::&::Comment here&::&::&:: is the same exact thing, but is that easier to find?

    One last thing. Remember when I said ALWAYS use :: instead of REM. Well here's a good reason. You will notice that I don't put a space between the :: and the first letter of the comment. You can do this with :: HOWEVER, with REM you cannot do this. So in reality, to keep files smallers, ::. actually is 2 times a smaller comment than REM. Example below...

    REM Comment here
    ::Comment here

    Notice you need an extra byte for the extra letter M in REM, and an extra byte for the space between the letter M and the first letter of the comment.

    NOTE: Remember, when setting a variable you use the name without the %'s, like SET foo=Hello Batch! But when you are referencing the set variable foo, you have to use %'s around it, like %foo% If you reference a variable that does NOT exist, mostly likely a error will be generated.


    Click here to continue





    Questions? Ask in the forum or email me.

    For the Privacy Policy, click here.
      
    Past Articles
  • Build your own Apple Clone
  • AllofMP3 Review
  • Tutorial to Basic Windows 2000 DOS
  • Extracting and joining MPG2 files from SVCD
  • Modifying your Windows XP Boot Logo
  • Unlocking WinXP's setupp.ini
  • Making a Full Screen Bios Logo
  • Making your WinMe CD bootable
  • Auto-insert your Win9x serial
  • Auto-insert your Office2kserial
  • Why FedEx Sucks