Shell script for running Java programs under Linux

Source: Internet
Author: User

Vim creates a new shell file, such as my file named Java_run, which reads:

echo "Please enter the Java file path you want to compile:"

Read Path

#分离路径和文件名
var1= ' dirname $path ' #路径
Var2= ' basename $path ' #文件名
CD $var 1
Javac $var 2
Java ${var2%.*} #去掉文件名的后缀

RM ${var2%.*}.class

OK, save quit vim.

chmod 777 Java_run #加可执行的权限

run the script,./java_run.


extension: If you want to make it your own command (just like LS), here are the following methods:

Home directory (that is, login user directory) Create a new directory, named Bin bar, copy java_run files to the directory, edit the. profile file, add at the end:

Path= $PATH: $HOME/bin
Save exit. After you type the command java_run can see the same effect as./java_run.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.