help-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Controlling script execution without environment variables based on


From: Richard Bonner
Subject: Re: Controlling script execution without environment variables based on
Date: Fri, 16 May 2008 14:32:28 +0000 (UTC)

John Bartley K7AAY (john.bartley@gmail.com) wrote:
> 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.

***   I have not used grep. Is it just a text string for which you are
looking? If so:

TYPE filename.ext | FIND "string"
IF ERRORLEVEL 1 GOTO JUST-DO-IT

:DON'T-DO-IT
(put commands here to perform if string not found)
GOTO OVER-IT

:JUST-DO-IT
(put commands here to perform if string is found)

:OVER-IT

         Richard Bonner
http://www.chebucto.ca/~ak621/DOS/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]