bash bash脚本编译java

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8264388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:06:28  来源:igfitidea点击:

bash script compile java

javabashshellcompilation

提问by drunkmonkey

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)

我需要编写一个 bash 脚本来编译我的 java 程序。我知道这有点人为,但这是家庭作业。(虽然我不确定bash脚本是否被标记,只是用于自动标记系统)

I only have one java file test.javaand 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.shand bash build.shboth gave me errors. Can anyone offer any help?

并保存为build.sh,我试图从终端运行这个既sh build.shbash build.sh两个给我的错误。任何人都可以提供任何帮助吗?

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;}'

回答by Gian

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?

看起来您已将脚本保存为富文本 (RTF),而不是纯文本。尝试使用您最喜欢的纯文本友好编辑器重新保存它?

回答by David W.

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 bozoscow-orkerscoworkersat 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.

抱歉所有的大写。我的工作中有一群bozos cow- orkers同事,他们认为写字板和记事本是上帝亲自祝福的完美程序编辑器。每周至少一次,我正在修复由使用这些程序的人引起的问题。

If you're on Windows, download Notepad++. If you want to learn a realprogram 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.

如果您使用的是 Windows,请下载Notepad++。如果你想学习一个真正的程序编辑器,试试VIM。如果您使用的是 Linux 或 Mac OS X,那么您的系统上已经安装了 VIM。如果您想要更面向 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 脚本。

回答by Denis Tulskiy

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,然后删除所有额外的东西。