I have a batch file that has to compare if A is greater than or equal B.
I also want to have a nice Text, printing something like this:
Is A >= B?
Thus i have something like this in my batch file:
@echo Is %A% >= %B%?
And here's the problem. The >= is interpreted as a pipe.
Trying to suppress it with a @ before echo or putting the output string in all sorts of quotation marks like
@echo `Is %A% >= %B%?`
@echo 'Is %A% >= %B%?'
@echo 'Is %A% >= %B%?'
@echo "Is %A% >= %B%?"
or trying to escape the ">" char with a backslash or slash doesn't work:
@echo %A% />= %B%
@echo %A% \>= %B%
The command is always trying to pipe A into B.
A workaround like swapping the two expressions into:
B < A
Also doesn't work. It gives a similar error. This time the pipe is used in the other direction.
It would be nice if pipes are not used, when @ is used in front of echo.
Or as an alternative, if echo understands the use of quotation marks like the GNU echo counterpart.
Or is there a solution for this?
The only solution I can think of right now would be to write out the >= as "greater than or equal". But I would like to do without that and prefer to use the above mathematical expression.
You have several "bugs" here:
FreeDOS doesn't allow
>or<in statementsThis is not a bug, as MS-DOS (and no other DOS) supports
>or<to compare values. Even Microsoft Powershell (Windows) uses-ltfor "less than" and-gtfor "greater than."Using
>or<in aREMstatement causes redirectionThis is standard MS-DOS behavior too. The MS-DOS 5.0 user manual (see p. 550) says:
Neither of these are bugs, but expected behavior on DOS.
The
IFbatch file conditional is documented to only support:where:
NOTnegates an expressionAnd valid expressions include:
ERRORLEVEL nto test if an error level (exit value) is equal to ns1==s2to test if the string s1 is equal to the string s2EXIST d:path\fileto test if the file exists at d:path\fileIf you are using FreeDOS and do not need to stick to built-in shell commands, consider using
VECHO.It is part of V8Power Tools and installed under FreeDOS 1.2 and later. V8Power Tools is what makes a a lot of magic happen. It is also what powers the user interface of FreeDOS Installer using batch files. VECHO is also what provides the colored text for the FreeDOS welcome message when booted.You can use it to do things like:
vecho "Is %A% >= %B%?"Or,
vecho Is %A% ">=" %B%?Or, add a little color like:
vecho Is %A% /fGreen ">=" /fGray %B%?Or, use double quotes by wrapping them in single quotes:
vecho ' ">" 'Or, use single qoutes by wrapping them in double qoutes:
vecho "Bob's house!"And, much much more. See
vecho /?Last edit: Shidel 2023-05-16
I am sure you find a reason why it is not identical with https://sourceforge.net/p/freedos/bugs/145/ .
I must admit that I also do not understand its sense.
@ fritz : Thanks for the link to bug 145 with the same answer about redirection inside a
REMstatementIf Oliver wants to implement "less than" or "greater than" tests in DOS, the standard way to do it is with a separate command line utility to do the test for you and return the result in the error level (exit code). For example, let's say you had a
CMPR("compare") command line tool like:where expr was something like:
LT: n is less than mLE: n is less than or equal to mGT: n is greater than mGE: n is greater than or equal to mEQ: n is equal to mThen you could do something like:
or:
.. but you would need to write the
CMPRprogram to do that. There is nothing like this included in FreeDOS, because this need is so incredibly rare in batch programming.If you need a CMPR program, I wrote a very simple implementation for you. You can find it at:
https://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/util/user/
I will close this bug, since it is not really a bug.
The CMPR tool is a very simple "one-off" program that fit this specific need. I don't think it's something that we would include in FreeDOS - certainly not in the form it is right now. Adding text output like you suggest actually adds to the size and complexity of the program (because of internationalization, etc). But maybe the functionality of CMPR could be added to some other "batch tool."
Closed because this is expected DOS behavior
Hi Oliver,
There is now a new tool called VTEST that is part of V8Power Tools. It supports 64-bit signed numerical and string comparisons as well as file system tests.
Things like this are possible:
vtest /tf %A /lt %B /gt %C /and %B /ne %DWhich would evaluate as:
/tfDisplay TRUE, FALSE or ERROR when finished.%A /lt %Bis %A less than %B%B /gt %Cis %B greater than %C/andEnd of First Expression, Evaluate next expression.%B /ne %Dis %B not equal to %DTRUE if both the first and second parts are true.
It is available in the latest V8Power Tools package at https://fd.lod.bz/repos/current/pkg-html/v8power.html
:-)
Jerome
Last edit: Shidel 2023-06-16