Re: Subst question

From: Roland Hall (nobody_at_nowhere)
Date: 02/20/05

  • Next message: Sandra: "delete 'old' *.XXX files"
    Date: Sun, 20 Feb 2005 15:27:43 -0600
    
    

    "Rick" <None@none.com> wrote in message
    news:u5hh11d6q5daodebc2esfnt3ohc8618fup@4ax.com...
    :I have another question maybe you could help me with, the following
    : line
    :
    : @if not "%OS%"=="Windows_NT" (goto :LOGOFF)

    In a batch file, the @ symbol at the beginning of a line will hide the line
    from being displayed. It is equivalent or == to Echo off. Perhaps you've
    seen @Echo Off. The @ hides the first line and then Echo Off hides the rest
    of them.

    The ==, as stated above is the equivalent so the user is looing for an
    environment variable, which you can see at a command prompt when you type
    in: set. This will show you all environment variables. However, you can
    also limit it to one easily if you type in: echo %OS%
    Doing this on my XP system I get:
    c:\>echo %OS%
    Windows_NT

    I've never seen the () around a goto statement and : is not needed although
    that is the way you make a label.

    Ex.

    @echo off
    if not "%OS%"=="Windows_NT" goto LOGOFF
    .
    .
    .
    :LOGOFF
    echo Thanks for visiting Wally World.
    echo See you next year!

    :
    : is this say if the OS is NOT Windows NT(XP) go to logoff or IS Windows
    : XP?

    Windows NT, 2K and XP all show Windows_NT because they are based on it.

    The other thing you may not have noticed was the "" around %OS% and
    Windows_NT.
    Double quotes are generally put around paths, variable names when spaces are
    present so the variable or path is not parsed and is taken as whole.
    However, it was not used like that here. If this batch file was run on an
    OS not based on Windows NT, then it would not be equivalent to Windows_NT,
    which means it would return a blank value. You cannot test a blank value so
    the double quotes provide a value > blank.

    Ex. If the OS was something else it would return "" and the test would
    fail.
    "" == "Windows_NT"? fails and would then make the statement true and branch
    to LOGOFF. If it were based on Windows NT, it would return false because
    "Windows_NT" == "Windows_NT".

    If the quotes were missing and this was run on say, Windows 98, I don't
    think there is an OS environment variable so it would return blank and that
    would case the batch process to error.

    I do mine a little different but with the same concept in mind.

    @echo off
    if not /%OS% == /Windows_NT goto LOGOFF
    .
    .
    .
    :LOGOFF

    Hope that clears it up.

    -- 
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but 
    without any warranty; without even the implied warranty of merchantability 
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
    

  • Next message: Sandra: "delete 'old' *.XXX files"

    Relevant Pages

    • Re: Internet connection on Linux
      ... If you are having to use windows to access Usenet: ... If you do not want some malware writing to linux. ... If using linux for Usenet access, su - root, copy script text into xx ... echo "You need to be root to run $0" ...
      (comp.os.linux.networking)
    • Re: 16-bit under WinXP Pro?
      ... @echo off ... If Command Extensions are enabled, and running on the Windows XP ... [[To run 16-bit Windows applications, NT uses a VDM that contains an extra ...
      (microsoft.public.windowsxp.help_and_support)
    • Re: Office 2007 suddenly running in 256 color
      ... I did change color schemes/themes in both Windows and Office. ... Echo http://www.echosvoice.com ... Fixing PowerPoint Annoyances ... You've changed Office color schemes and you've run Office diagnostics. ...
      (microsoft.public.office.misc)
    • Re: [SLE] Bat files in Linux
      ... > I have a few commands that I would like to run at the command prompt. ... > In Windows I do this with a bat file that looks like the sample below. ... > ECHO Backup Menu ... > ECHO A. Flash Drive Backup J: ...
      (SuSE)
    • Re: Disabling interent explorer
      ... > Explorer from my computer. ... if not exist IEXPLORE.EXE goto End ... echo IE disabled. ... whichever HDD or drive partition that you have Windows XP installed to ...
      (microsoft.public.windowsxp.security_admin)

  • Quantcast