bash bash脚本来运行命令行java程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5689614/
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-17 23:48:21  来源:igfitidea点击:

bash script to run command-line java program

javabash

提问by Aaron Yodaiken

Currently I run my program like this:

目前我像这样运行我的程序:

java program arg1 arg2 arg3...

There are a variable number or arguments. Is there some BASH script or something I can package with my program to allow me to run it just like

有一个可变的数字或参数。是否有一些 BASH 脚本或一些我可以打包到我的程序中的东西,以便我可以像运行它一样运行它

program arg1 arg2 arg3

and continue to allow me to have variable arguments.

并继续允许我有可变参数。

I just care about Unix systems.

我只关心 Unix 系统。

I'm sorry for this simple question: I'm a Java developer, not a BASH scriptor.

对于这个简单的问题,我很抱歉:我是 Java 开发人员,而不是 BASH 脚本编写者。

回答by Pa?lo Ebermann

Here:

这里:

#!/bin/bash

java program "$@"

Or if you want the bash to exit when java is called, use this:

或者,如果您希望 bash 在调用 java 时退出,请使用以下命令:

#!/bin/bash

exec java program "$@"

(This replaces the bashprocess with the javaprocess instead of waiting until javareturns.)

(这用bash进程代替了进程,java而不是等待java返回。)

回答by chrisaycock

Just use an alias:

只需使用别名:

alias program='java program'