File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Linux / UNIX and the fly likes porting a .bat file to unix Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "porting a .bat file to unix" Watch "porting a .bat file to unix" New topic

porting a .bat file to unix

Christopher Arthur
Ranch Hand

Joined: Mar 09, 2004
Posts: 149

How do I do in UNIX what I do with a .BAT file in DOS?

I'm trying to distribute my java program, and for windows I have a .bat file with this command to run my program:

java -classpath $CLASSPATH$;./bin/harmony.jar;./bin/commons-net-1.2.2.jar arthur.kepler.Controller

my guess is that I do the following command in UNIX/LINUX:

java -classpath {$CLASSPATH}:./bin/harmony.jar:./bin/commons-net-1.2.2.jar arthur.kepler.Controller

But, I don't know what kind of file to stick it in.

Any suggestions?


Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Is that correct syntax for a BAT file, with those dollar signs around $CLASSPATH$ ? Thought you had to use percent (%) signs.

Anyway, your UNIX translation is close; the brackets (which are optional) aren't positioned quite right, and there's a special line that you generally put at the beginning, as so:

The file's name doesn't matter, but there's an executable file attribute that normally should be set. Don't know how to do this when packing things from Windows, though.

[Jess in Action][AskingGoodQuestions]
Rick Portugal
Ranch Hand

Joined: Dec 17, 2002
Posts: 243
To create the equivilent of a .bat file on Unix, you would create a shell script. You have a choice of which shell to use. Bourne shell scripts (like the example above) normally have the suffix .sh. So you could call that shell script

Korn shell scripts use the suffix .ksh (e.g., christopher.ksh). Bash shell scripts end in .bash. There are others too.

The syntax of your script will depend upon which shell you choose to use. There are lots of online resources available to help you get the syntax right.

Everybody has their own preferences. Personally, I recommend using the Korn shell.

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Most of the time using the Bourne shell makes the most sense (especially for something as simple as this) because everybody's guaranteed to have it. Not everybody's going to have ksh (for example, the Mandrake 10 laptop I'm typing on doesn't.) If you're writing a major application as a set of shell scripts, it's not a big deal to use one of the more exotic shells; but to make the user install ksh or zsh or whatnot just to execute your Java app is not going to win you any fans.

I wanted to make it clear that the "#!" line at the top of the script determines what shell is going to be used, not the name of the file. Using .sh is a very weak convention, if it's a convention at all, and using .ksh, .bash. .csh is weaker still. Most shell scripts (like most UNIX executables) have names with no "extension".
I agree. Here's the link:
subject: porting a .bat file to unix
It's not a secret anymore!