Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

IS there any way to make Windows scripts (BAT) files run on a Unix machine? Like importing a function or a library for example, which is only recognised on the Unix OS, but has no effect when run in Windows.

OR it could be possible to write both sets of commands in the same file and do something like this:

If OS = 'Windows' then execute between lines A and B
else execute between lines C and D
share|improve this question
I think the second method is probably better since any misinterpretation of characters like '/' or '\' can be avoided. – Jay Feb 5 '13 at 7:04
.bat or .cmd Windows batch files are really meant for Windows only. Though you could possibly run (*)sh scripts on Windows via cygwin, you should consider using something else (like Python?) – Alvin Wong Feb 5 '13 at 7:07
what exactly are you trying to accomplish? – Keltari Feb 5 '13 at 15:30
@AlvinWong But python programs require python to be installed :( – Jay Feb 7 '13 at 3:24
@Keltari I am trying to make a database health check program that performs certain tasks and produces a report with the results of each task. – Jay Feb 7 '13 at 3:26

You can't natively run a BAT script on UNIX/Linux. But you could try Wine:

Wine (originally an acronym for "Wine Is Not an Emulator") is a compatibility layer capable of running Windows applications on several POSIX-compliant operating systems.

You can download Wine installers for several Linux and BSD distros and for Solaris here (you will need to compile the source for other UNIX flavors, though).

Once Wine is installed and configured, copy the BAT script to your UNIX/Linux computer and run it like this (from

# wine cmd < path/to/your/file.bat
# wine start path/to/your/file.bat
# wine cmd /c path/to/your/file.bat

Notice that though Wine will do its best to execute the scripts there are portability issues like filesystem case-sensitivy, path names, text encoding issues, etc. that may break things.

That's why I'd recommend that you use Wine for legacy scripts. New scripts are best written in a platform independent language, like Perl or Python.

share|improve this answer
wine wouldn't be an option, since my script wouldn't only run on designated machines. I may or may not have admin rights to install wine anyway. – Jay Feb 7 '13 at 3:27

There are plenty of alternative scripting languages that work on Windows, UNIX, Linux, as well as other OSs.

Perl would probably be the best choice. Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl can do just about anything OS related that you would want, not to mention Comprehensive Perl Archive Network (CPAN). CPAN is an archive of over 25,000 distributions of software written in Perl, as well as documentation for it. There are "plugins" for just about everything you could imagine. Integration to all the major databases, popular software products, and much more.

Python, Ruby, Lua, are other examples.

Another possible solution would be to run UNIX/Linux scripts on Windows. This can be accomplished with Cygwin. In short, Cygwin is a collection of tools which provide a Linux look and feel environment for Windows.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .