Re: Controlling script execution without environment variables based on file content

Manuel Collado <[email protected]>
Newsgroups gmane.comp.gnu.utils
Organization RedIRIS
Message-ID <[email protected]>
John Bartley K7AAY escribió:
> Need to peek in a file, and based on what you see, conditionally
> execute a subroutine in an XP batch file? Tired of trying to figure
> out how to stuff a value into an environment variable?  Instead, use
> GNU grep from gnuwin32.sourceforge.net and try:
> 
> grep CONDITION filename && goto JUST-DO-IT
> rem DON'T DO IT - put commands here to perform if condition not met
> goto OVER-IT
> :JUST-DO-IT
> put commands here to perform if condition met
> :OVER-IT
> 
> The portion of the first command line after the && only executes if
> the grep was successful. If grep found what you were looking for, the
> script branches to JUST-DO-IT. If grep did not find what you were
> looking for, the next line executes, and all lines below it, until you
> hit the second goto which sends you over the the JUST-DO-IT branch,
> and rejoins the script at OVER-IT.

The script can be rewritten as:

grep -q CONDITION filename
if not ERRORLEVEL 1 (
    put commands here to perform if CONDITION found
) else (
    put commands here to perform if CONDITION not found
)

Yes, this is for Windows XP.

Hope this helps.
-- 
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.