954,184 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need help with BASH to MS-DOS Batch conversion.

bash:

#!/bin/bash

DOMAIN=mydomain.com

for client in ServerA ServerB ServerC ServerD
do
xhost +$client.$DOMAIN
done


MS-DOS:
@echo off
for..... crap.....

I can't seem to get the for loop to work properly. Has anyone had much experience with batch files in DOS? I realize that running xhost inside of a batch file sounds silly, but there is a need for it in this situation. :)

I wouldn't doubt if the first response is RTFM, or whatever, but there is no "man" in ms-dos, and doing "for /?" didn't help at all. :)

i686-linux
Posting Whiz in Training
210 posts since Mar 2004
Reputation Points: 87
Solved Threads: 12
 

Hi I think the following should work:

SET DOMAIN=mydomain.com
FOR %%A IN (ServerA ServerB ServerC ServerD) DO xhost +%%A%.%DOMAIN%


You may need to play with it a little to get it working exactly right but that is the basic syntax.

HTH

Ben

liliafan
Junior Poster
117 posts since Apr 2004
Reputation Points: 66
Solved Threads: 3
 

That yields the same problem that I was having:

%%A was unexpected at this time.

i686-linux
Posting Whiz in Training
210 posts since Mar 2004
Reputation Points: 87
Solved Threads: 12
 
That yields the same problem that I was having: %%A was unexpected at this time.

Hmmmm running on windows XP that works fine, what version of windows are you using?

Additionally is this from a bat file or are you testing on the commandline? On the command line %%A becomes %A.

From checking for / do on commandline requires an NT class OS.

liliafan
Junior Poster
117 posts since Apr 2004
Reputation Points: 66
Solved Threads: 3
 

Using Windows 2000 server. I was testing it at the command line. That was the problem. Thanks!

i686-linux
Posting Whiz in Training
210 posts since Mar 2004
Reputation Points: 87
Solved Threads: 12
 

NP glad to help.

Ben

liliafan
Junior Poster
117 posts since Apr 2004
Reputation Points: 66
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You