• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

porting a .bat file to unix

 
Christopher Arthur
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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?

Kindly,

Chris
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rick Portugal
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 christopher.sh.

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
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic