• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 431
  • Last Modified:

Converting MSDOS batch file to Linux shell script

Hi all,

I'm new to Linux, and I've got one little problem.

I have a batch file in Windows that I wrote to compile and run some Java files. However, I also need to do that in Linux. I know that it is called shell script, but I know nothing about it.

Here is the batch file:

----------------------------------------------------------------------
@echo off
if exist "%JAVA_HOME%\bin\javac.exe" goto okExecute
if exist "%PATH%\javac.exe" goto okExecute
if not exist "%JAVA_HOME%\bin\javac.exe" goto notExecute
if not exist "%PATH%\javac.exe" goto notExecute

:notExecute
echo JAVA_HOME environment variable not found
goto end

:okExecute
javac -sourcepath src -classpath classes src\compiler\Lex.java -d classes
java -classpath classes compiler.Lex %1 %2
goto end

:end

----------------------------------------------------------------------

I would really appreciate if you help me!

Thanks in advance.
0
brunoguimaraes
Asked:
brunoguimaraes
  • 2
1 Solution
 
jstretchCommented:
shell scripts usually end in the .sh extension, they are simply a text file full of commands you'd type in the command prompt.

EG: If you wanted to compile 2 java files in your home directory, this may be what you script looks like:

javac /home/myname/javafile1.java
javac /home/myname/javafile2.java


Then, you'd save this file maybe as /home/myname/compile.sh

To run it you would then type in the terminal/prompt:
# ./home/myname/compile.sh


If you get a permission error type:
# chmod 777 /home/myname/compile.sh

You can also set env variables jus tlike windows for JAVA_HOME etc... but before I ramble on just read:

http://www.freeos.com/guides/lsst/ch02sec01.html
0
 
TintinCommented:
Shell equiv (more or less) is:

#!/bin/sh
if [ -z "$JAVA_HOME" ]
then
  echo "JAVA_HOME environment variable not set"
  exit 1
fi

$JAVA_HOME/bin/javac -sourcepath src -classpath classes src/compiler/Lex.java -d classes
$JAVA_HOME/bin/java -classpath classes compiler.Lex $1 $2

0
 
brunoguimaraesAuthor Commented:
Sorry I took so long to answer back.

Thanks for your help Tintin. I accidentally gave you a grade B. How can I change it to A?
0
 
TintinCommented:
You can post a request in the "Community Support" forum for any changes.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now