Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
Lutz

DOS Scripts: OR statement?

Recommended Posts

So, for a bunch of reasons I won't go into, I need to create some DOS scripts (.BAT files). I've been able to do what I want, but it would be very handy to be able to OR inside an if-check. What I would like to do is this:

IF [var1]==[value1] (OR) [var1]==[value2] ( do something )

Is there a way? Or am I forced to use two if-checks, or goto statements, etc.?

Share this post


Link to post

The closest thing I can think of is using CHOICE and ERRORLEVEL (which is really just IF/GOTO statements). I am not aware of an OR statement in MS-DOS.

Using multiple IF/GOTO statements is your only way.

Share this post


Link to post

I don't think there's an OR operator in plain DOS (command.com), but I know 4DOS had one. I'm not sure about cmd.exe in Windows.

The easiest way to emulate it is to have two consecutive IF statements that run the same command, but that has the side effect of executing the command twice if both conditions are true. Otherwise:

IF var1==value1 GOTO DOSTUFF
IF var2==value2 GOTO DOSTUFF
:RET
(batch file continues here)
...
GOTO END
:DOSTUFF
(insert command here)
GOTO RET
:END

Share this post


Link to post

You could use KiXtart, a more advanced scripting language. It's syntax is very similar batch files and allows the use of IF/OR/ELSE statements.

We use kix for our login scripts at work.

Share this post


Link to post

Yeah, I'd suggest either using multiple IF/GOTO statements, or look into using an alternative shell. 4DOS had OR and CASE statements, and will likely be the one closest to DOS. If you're using XP's cmd.exe though, it's worth noting it doesn't have all the old MS-DOS commands, including CHOICE.

If you want more power, you could look into using Bash. I've even used it in conjunction with GNU Make for Doom levels.

Or if you wanted to be masochistic, you could always use Windows PowerShell.

Share this post


Link to post

Oh man, I could've helped you with this like 10 years ago.

I used to menu everything on people's PCs whether they liked it or not.

But in the same way I used to be able to play Fur Elise and now can't play Jingle Bells, BATs are a long dead artform of mine :(

Errorlevel sounds familiar in a variable input/output/choice context though.

Share this post


Link to post
exp(x) said:

I shall taunt you with the power of bash.


May I take this time to say that "bash" is the dumbest acronym for a shell, ever.

Then again, PowerShell is pretty stupid, too.

Share this post


Link to post
Csonicgo said:

May I take this time to say that "bash" is the dumbest acronym for a shell, ever.

Then again, PowerShell is pretty stupid, too.

Yeah, I think PowerShell is a lot worse than Bash. At least Bash is a play on words, and a bit better than the name "Korn Shell", which is fun but never made sense to me.

Share this post


Link to post

[EDIT]
So, for a bunch of reasons I won't go into, I need to create some DOS SCRIPTS (.BAT FILES).
[/EDIT]

Sorry, but for several reasons, I cannot explore other shells; I'm stuck with DOS. As such, though no one has come out and said it, I get the impression that the answer is no. So, thanks to you all -- I guess I'll do it the old fashioned (UGLY) way.

Share this post


Link to post

create an empty file upon successful conditional testing and then test for the existence of the file to stop further IF statements. Next, delete the intermediary file.

Share this post


Link to post

Lutz said:
As such, though no one has come out and said it, I get the impression that the answer is no.

Both Planky and I said there was no OR operator (well, I qualified mine with "I think" since I didn't have a real DOS system or any manuals nearby to check)...

Zaldron said:
create an empty file upon successful conditional testing and then test for the existence of the file to stop further IF statements. Next, delete the intermediary file.

This avoids spaghetti code with GOTO, but I can see a few (relatively rare) cases where it can fail: chosen location for temporary file is read-only, the root directory is full (if the chosen location is a drive's root) or the disk is full (in the even rarer case that a non-root directory needs to grow on a full disk).

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×