Converting MSDOS batch file to Linux shell script

Posted on 2005-05-05
Last Modified: 2010-04-21
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

echo JAVA_HOME environment variable not found
goto end

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



I would really appreciate if you help me!

Thanks in advance.
Question by:brunoguimaraes
    LVL 6

    Expert Comment

    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/
    javac /home/myname/

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

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

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

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

    Accepted Solution

    Shell equiv (more or less) is:

    if [ -z "$JAVA_HOME" ]
      echo "JAVA_HOME environment variable not set"
      exit 1

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

    LVL 9

    Author Comment

    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?
    LVL 48

    Expert Comment

    You can post a request in the "Community Support" forum for any changes.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
    The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now