Reputation: 1181
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;}'
Upvotes: 1
Views: 8458
Reputation: 107040
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.
Upvotes: 3
Reputation: 13955
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?
Upvotes: 5
Reputation: 19177
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.
Upvotes: 1