简体   繁体   English

bash脚本编译Java

[英]bash script compile java

I need to write a bash script to compile my java program. 我需要编写一个bash脚本来编译我的Java程序。 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) (尽管我不确定bash脚本是否已被标记,仅用于自动标记系统)

I only have one java file test.java and the script is to only search its own directory: I tried: 我只有一个Java文件test.java ,脚本仅搜索其自己的目录:我试过:

#!/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. 并保存为build.sh ,我尝试从终端运行它,因为sh build.shbash build.sh都给了我错误。 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;}'

It looks like you've saved your script as rich text (RTF), not plain text. 看起来您已将脚本另存为RTF(富文本格式)而不是纯文本格式。 Try re-saving it using your favourite plain-text-friendly editor? 尝试使用您喜欢的纯文本友好编辑器重新保存它?

Silly question, but what editor did you use to edit your Java program? 愚蠢的问题,但是您使用什么编辑器来编辑Java程序?

It looks like your Java program is in RTF format and not plain ascii. 看来您的Java程序是RTF格式,而不是纯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. 我的工作中有很 多布尔佐斯 牛或 工友 ,他们认为Wordpad和Notepad受到上帝本人的祝福,是一对完美的程序编辑器。 At least once per week, I'm fixing problems caused by someone using these programs. 每周至少一次,我要解决由使用这些程序的人引起的问题。

If you're on Windows, download Notepad++ . 如果您使用的是Windows,请下载Notepad ++ If you want to learn a real program editor, try VIM . 如果您想学习真正的程序编辑器,请尝试VIM If you're on Linux or Mac OS X, you already have VIM installed on your system. 如果您使用的是Linux或Mac OS X,则您的系统上已经安装了VIM。 If you want a more GUI oriented program editor, try downloading JEdit . 如果您希望使用更多面向GUI的程序编辑器,请尝试下载JEdi​​t

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. 只要确保您下次需要编辑程序时就使用真正的程序编辑器,即使它只有两行shell脚本也是如此。

It seems like the editor you're using adds some extra information to the file: 您正在使用的编辑器似乎在文件中添加了一些额外的信息:

{\\fonttbl\\f0\\fmodern\\fcharset0 Courier;\\f1\\fswiss\\fcharset0 Helvetica;}' {\\ 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. 尝试使用简单的文件(例如nano打开文件,然后删除所有多余的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM