1

I need to write a bash script to compile my java program. I know it's a bit artificial but it is homework. (although I'm not sure the bash script is even marked, just used for the automated marking system)

I only have one java file test.java and the script is to only search its own directory: I tried:

#!/bin/bash          
javac test.java

and saved as build.sh, i tried to run this from the terminal as both sh build.sh and bash build.sh both gave me errors. Can anyone offer any help?

included errors:

build.sh: line 1: {rtf1ansiansicpg1252cocoartf1038cocoasubrtf350: command not found
build.sh: line 2: syntax error near unexpected token `}'
build.sh: line 2: `{\fonttbl\f0\fmodern\fcharset0 Courier;\f1\fswiss\fcharset0 Helvetica;}'
6
  • what error? show the error message. Commented Nov 25, 2011 at 2:49
  • 1
    Did you chmod u+x it? If so, ./build.sh should be enough. Commented Nov 25, 2011 at 2:50
  • We would need to know what the errors are. You should also make sure your bash script is executable by running: chmod +x build.sh Could also be that javac isnt on your path. Check that the java compiler bin directory is on your path. Commented Nov 25, 2011 at 2:50
  • Are you sure it's test.java and not Test.java(Which is preferred coding standard). Commented Nov 25, 2011 at 2:51
  • I've added the permissions to make it executable. It's test.java, I know by convention it should be Test. but I'm only experimenting with the script right now. I ran the javac test.java from the terminal and it compiled fine and i was able to run it fine. Commented Nov 25, 2011 at 2:55

3 Answers 3

5

It looks like you've saved your script as rich text (RTF), not plain text. Try re-saving it using your favourite plain-text-friendly editor?

Sign up to request clarification or add additional context in comments.

Comments

3

Silly question, but what editor did you use to edit your Java program?

It looks like your Java program is in RTF format and not plain ascii.

If you tell me you used Wordpad, I'm going to track you down, fly to your town, come to your work, and slap you silly. DO NOT EVER USE A NON-PROGRAM EDITOR FOR EDITING A PROGRAM.

Sorry for the all capitalizations. I have a bunch of bozos cow-orkers coworkers at my work who think Wordpad and Notepad have been blessed by God himself as the perfect pair of program editors. At least once per week, I'm fixing problems caused by someone using these programs.

If you're on Windows, download Notepad++. If you want to learn a real program editor, try VIM. If you're on Linux or Mac OS X, you already have VIM installed on your system. If you want a more GUI oriented program editor, try downloading JEdit.

Just make sure you use a true program editor the next time you need to edit a program -- even if it's nothing but a two line shell script.

Comments

1

It seems like the editor you're using adds some extra information to the file:

{\fonttbl\f0\fmodern\fcharset0 Courier;\f1\fswiss\fcharset0 Helvetica;}'

what editor are you using? Try opening the file with something simple, like nano, and remove all the extra stuff.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.